home.nix 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. {
  2. config,
  3. lib,
  4. pkgs,
  5. ...
  6. }: rec {
  7. # Nicely reload system units when changing configs
  8. systemd.user.startServices = "sd-switch";
  9. gtk = {
  10. enable = true;
  11. font = {
  12. name = "SF Pro Rounded";
  13. size = 11;
  14. };
  15. iconTheme = {
  16. package = pkgs.whitesur-icon-theme;
  17. name = "WhiteSur-dark";
  18. };
  19. theme = {
  20. name = "WhiteSur-Dark";
  21. package = pkgs.whitesur-gtk-theme;
  22. };
  23. cursorTheme = {
  24. name = "capitaine-cursors-white";
  25. size = 24;
  26. package = pkgs.capitaine-cursors;
  27. };
  28. gtk2.extraConfig = "gtk-cursor-theme-size=24";
  29. gtk3.extraConfig."gtk-cursor-theme-size" = 24;
  30. gtk4.extraConfig."gtk-cursor-theme-size" = 24;
  31. };
  32. home.file = {
  33. ".icons/default/index.theme".text = ''
  34. [icon theme]
  35. Name=Default
  36. Comment=Default Cursor Theme
  37. Inherits=${gtk.cursorTheme.name}
  38. '';
  39. };
  40. dconf.settings = {
  41. "org/gnome/desktop/interface" = {
  42. gtk-theme = "${gtk.theme.name}";
  43. icon-theme = "${gtk.iconTheme.name}";
  44. cursor-theme = "${gtk.cursorTheme.name}";
  45. };
  46. };
  47. programs = {
  48. direnv = {
  49. enable = true;
  50. nix-direnv.enable = true;
  51. };
  52. exa = {
  53. enable = true;
  54. enableAliases = false;
  55. };
  56. git = {
  57. enable = true;
  58. userEmail = "ludovicopiero@pm.me";
  59. userName = "Ludovico Piero";
  60. signing = {
  61. key = "3911DD276CFE779C";
  62. signByDefault = true;
  63. };
  64. extraConfig = {
  65. init.defaultBranch = "main";
  66. pull.rebase = false;
  67. };
  68. aliases = {
  69. a = "add -p";
  70. co = "checkout";
  71. cob = "checkout -b";
  72. f = "fetch -p";
  73. c = "commit -s";
  74. p = "push";
  75. ba = "branch -a";
  76. bd = "branch -d";
  77. bD = "branch -D";
  78. d = "diff";
  79. dc = "diff --cached";
  80. ds = "diff --staged";
  81. r = "restore";
  82. rs = "restore --staged";
  83. st = "status -sb";
  84. # reset
  85. soft = "reset --soft";
  86. hard = "reset --hard";
  87. s1ft = "soft HEAD~1";
  88. h1rd = "hard HEAD~1";
  89. # logging
  90. lg = "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit";
  91. plog = "log --graph --pretty='format:%C(red)%d%C(reset) %C(yellow)%h%C(reset) %ar %C(green)%aN%C(reset) %s'";
  92. tlog = "log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative";
  93. rank = "shortlog -sn --no-merges";
  94. # delete merged branches
  95. bdm = "!git branch --merged | grep -v '*' | xargs -n 1 git branch -d";
  96. };
  97. };
  98. gpg = {
  99. enable = true;
  100. homedir = "${config.xdg.configHome}/gnupg";
  101. };
  102. home-manager.enable = true;
  103. nix-index.enable = true;
  104. starship = {
  105. enable = true;
  106. settings = import ./config/starship.nix {inherit lib;};
  107. };
  108. fish = let
  109. _ = lib.getExe;
  110. in {
  111. enable = true;
  112. functions = {
  113. gitignore = "curl -sL https://www.gitignore.io/api/$argv";
  114. fish_greeting = ""; # disable welcome text
  115. run = "nix run nixpkgs#$argv";
  116. "watchLive" = let
  117. args = "--hwdec=dxva2 --gpu-context=d3d11 --no-keepaspect-window --keep-open=no --force-window=yes --force-seekable=yes --hr-seek=yes --hr-seek-framedrop=yes";
  118. in "${_ pkgs.streamlink} --player ${_ pkgs.mpv} --twitch-disable-hosting --twitch-low-latency --player-args \"${args}\" --player-continuous-http --player-no-close --hls-live-edge 2 --stream-segment-threads 2 --retry-open 15 --retry-streams 15 $argv best -a --ontop -a --no-border";
  119. };
  120. interactiveShellInit = with pkgs; ''
  121. ${_ starship} init fish | source
  122. ${_ any-nix-shell} fish --info-right | source
  123. ${_ direnv} hook fish | source
  124. '';
  125. shellAliases = with pkgs; {
  126. "bs" = "pushd ~/.config/nixos && doas nixos-rebuild switch --flake .#sforza && popd";
  127. "bb" = "pushd ~/.config/nixos && doas nixos-rebuild boot --flake .#sforza && popd";
  128. "hs" = "pushd ~/.config/nixos && home-manager switch --flake .#ludovico && popd";
  129. "cat" = _ bat;
  130. "config" = "cd ~/.config/nixos";
  131. "ls" = "${_ exa} --icons";
  132. "l" = "${_ exa} -lbF --git --icons";
  133. "ll" = "${_ exa} -lbGF --git --icons";
  134. "llm" = "${_ exa} -lbGF --git --sort=modified --icons";
  135. "la" = "${_ exa} -lbhHigUmuSa --time-style=long-iso --git --color-scale --icons";
  136. "lx" = "${_ exa} -lbhHigUmuSa@ --time-style=long-iso --git --color-scale --icons";
  137. "tree" = "${_ exa} --tree --icons";
  138. "nv" = "nvim";
  139. "mkdir" = "mkdir -p";
  140. "g" = "git";
  141. "gcl" = "g clone";
  142. "gd" = "g diff HEAD";
  143. "gpl" = "g pull";
  144. "gpsh" = "g push -u origin";
  145. "gs" = "g status";
  146. "record" = "${_ wl-screenrec} -f ${config.xdg.userDirs.extraConfig.XDG_RECORD_DIR}/$(date '+%s').mp4";
  147. "record-region" = "${_ wl-screenrec} -g \"$(${_ slurp})\"";
  148. "sudo" = "doas";
  149. "..." = "cd ../..";
  150. ".." = "cd ..";
  151. };
  152. };
  153. };
  154. services = {
  155. gpg-agent = {
  156. enable = true;
  157. pinentryFlavor = "gnome3";
  158. };
  159. };
  160. systemd.user = {
  161. timers.nix-index-db-update = {
  162. Timer = {
  163. OnCalendar = "weekly";
  164. Persistent = true;
  165. RandomizedDelaySec = 0;
  166. };
  167. };
  168. services.nix-index-db-update = {
  169. Unit = {
  170. Description = "nix-index database update";
  171. PartOf = ["multi-user.target"];
  172. };
  173. Service = let
  174. script = pkgs.writeShellScript "nix-index-update-db" ''
  175. export filename="index-x86_64-$(uname | tr A-Z a-z)"
  176. mkdir -p ~/.cache/nix-index
  177. cd ~/.cache/nix-index
  178. # -N will only download a new version if there is an update.
  179. wget -N https://github.com/Mic92/nix-index-database/releases/latest/download/$filename
  180. ln -f $filename files
  181. '';
  182. in {
  183. Environment = "PATH=/run/wrappers/bin:${lib.makeBinPath [pkgs.wget pkgs.coreutils]}";
  184. ExecStart = "${script}";
  185. };
  186. Install.WantedBy = ["multi-user.target"];
  187. };
  188. };
  189. xdg = let
  190. browser = ["firefox.desktop"];
  191. mailspring = ["Mailspring.desktop"];
  192. # XDG MIME types
  193. associations = {
  194. "application/x-extension-htm" = browser;
  195. "application/x-extension-html" = browser;
  196. "application/x-extension-shtml" = browser;
  197. "application/x-extension-xht" = browser;
  198. "application/x-extension-xhtml" = browser;
  199. "application/xhtml+xml" = browser;
  200. "text/html" = browser;
  201. "x-scheme-handler/about" = browser;
  202. "x-scheme-handler/chrome" = ["chromium-browser.desktop"];
  203. "x-scheme-handler/ftp" = browser;
  204. "x-scheme-handler/http" = browser;
  205. "x-scheme-handler/https" = browser;
  206. "x-scheme-handler/unknown" = browser;
  207. "x-scheme-handler/mailspring" = mailspring;
  208. "audio/*" = ["mpv.desktop"];
  209. "video/*" = ["mpv.dekstop"];
  210. "image/*" = ["imv.desktop"];
  211. "application/json" = browser;
  212. "application/pdf" = ["org.pwmt.zathura.desktop.desktop"];
  213. "x-scheme-handler/discord" = ["discordcanary.desktop"];
  214. "x-scheme-handler/spotify" = ["spotify.desktop"];
  215. "x-scheme-handler/tg" = ["telegramdesktop.desktop"];
  216. "x-scheme-handler/mailto" = mailspring;
  217. "message/rfc822" = mailspring;
  218. "x-scheme-handler/mid" = mailspring;
  219. };
  220. in {
  221. enable = true;
  222. cacheHome = config.home.homeDirectory + "/.cache";
  223. mimeApps = {
  224. enable = true;
  225. defaultApplications = associations;
  226. };
  227. userDirs = {
  228. enable = true;
  229. createDirectories = true;
  230. extraConfig = {
  231. XDG_SCREENSHOTS_DIR = "${config.xdg.userDirs.pictures}/Screenshots";
  232. XDG_RECORD_DIR = "${config.xdg.userDirs.videos}/Record";
  233. XDG_GAMES_DIR = "${config.home.homeDirectory}/Games";
  234. XDG_MISC_DIR = "${config.home.homeDirectory}/Code";
  235. };
  236. };
  237. };
  238. }