default.nix 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. { inputs, pkgs, lib, ... }:
  2. {
  3. imports = [
  4. # inputs.impermanence.nixosModules.impermanence
  5. inputs.disko.nixosModules.disko
  6. ./hardware-configuration.nix
  7. ./disko.nix
  8. # ./secrets.nix
  9. # ./services
  10. ];
  11. # System identification
  12. networking = {
  13. hostName = "odin";
  14. # Generate a unique host ID (you need to replace this with an actual string)
  15. # hostId = "12345678"; # Generate with `head -c 8 /etc/machine-id` and place result here
  16. useDHCP = lib.mkDefault true;
  17. # Firewall configuration for home server
  18. # firewall = {
  19. # enable = true;
  20. # allowedTCPPorts = [
  21. # 22 # SSH
  22. # 80 # HTTP
  23. # 443 # HTTPS
  24. # 2283 # Immich
  25. # ];
  26. # };
  27. };
  28. # Boot configuration
  29. boot = {
  30. # Use systemd-boot for UEFI systems
  31. loader = {
  32. systemd-boot.enable = true;
  33. efi.canTouchEfiVariables = true;
  34. grub.devices = [ "/dev/nvme0n1" ];
  35. timeout = 3;
  36. };
  37. # Kernel parameters for server workload
  38. kernelParams = [ "rootflags=compress=zstd:1,noatime" ];
  39. # Enable KSM for memory efficiency with containers
  40. kernel.sysctl = {
  41. "kernel.sysrq" = 1;
  42. "vm.swappiness" = 10;
  43. "net.core.default_qdisc" = "cake";
  44. };
  45. };
  46. # # Impermanence: reset root on boot
  47. # initrd.postDeviceCommands = lib.mkAfter ''
  48. # # Get device from disko config
  49. # DEVICE=/dev/disk/by-id/nvme-KINGSTON_SNV3S1000G_50026B7383CC0908-part2
  50. #
  51. # mkdir -p /mnt
  52. # mount -o subvol=/ $DEVICE /mnt
  53. #
  54. # # Create a directory for old roots if it doesn't exist
  55. # mkdir -p /mnt/old-roots
  56. #
  57. # # Move current root to old-roots with timestamp if it exists
  58. # if [[ -e /mnt/@root && ! -e /mnt/@root-blank ]]; then
  59. # timestamp=$(date --date="@$(stat -c %Y /mnt/@root)" "+%Y-%m-%d_%H:%M:%S")
  60. # mv /mnt/@root "/mnt/old-roots/@root-$timestamp"
  61. # fi
  62. #
  63. # # Function to recursively delete subvolumes
  64. # delete_subvolume_recursively() {
  65. # for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
  66. # delete_subvolume_recursively "/mnt/$i"
  67. # done
  68. # btrfs subvolume delete "$1"
  69. # }
  70. #
  71. # # Delete old roots older than 30 days
  72. # for i in $(find /mnt/old-roots/ -maxdepth 1 -mtime +30); do
  73. # delete_subvolume_recursively "$i"
  74. # done
  75. #
  76. # # Create fresh root from blank if needed or create blank if it doesn't exist
  77. # if [[ -e /mnt/@root-blank ]]; then
  78. # btrfs subvolume delete /mnt/@root || true
  79. # btrfs subvolume snapshot /mnt/@root-blank /mnt/@root
  80. # else
  81. # btrfs subvolume create /mnt/@root-blank
  82. # btrfs subvolume create /mnt/@root
  83. # fi
  84. #
  85. # umount /mnt
  86. # '';
  87. # };
  88. #
  89. # # Hardware optimizations
  90. # hardware = {
  91. # enableRedistributableFirmware = true;
  92. # cpu.amd.updateMicrocode = true;
  93. #
  94. # # Enable hardware acceleration for media processing
  95. # opengl = {
  96. # enable = true;
  97. # extraPackages = with pkgs; [
  98. # amdvlk
  99. # rocm-opencl-icd
  100. # ];
  101. # };
  102. # };
  103. #
  104. # # Power management for home server
  105. # powerManagement = {
  106. # enable = true;
  107. # cpuFreqGovernor = "ondemand";
  108. # };
  109. # Services configuration
  110. services = {
  111. # SSH configuration is managed in secrets.nix
  112. openssh = {
  113. enable = true;
  114. settings = {
  115. PasswordAuthentication = false;
  116. PermitRootLogin = "no";
  117. X11Forwarding = false;
  118. };
  119. # hostKeys = [ ];
  120. };
  121. # System monitoring
  122. # smartd = {
  123. # enable = true;
  124. # autodetect = true;
  125. # notifications.mail.enable = false; # Configure if you want email alerts
  126. # };
  127. # # Time synchronization
  128. # timesyncd.enable = true;
  129. #
  130. # # Btrfs maintenance
  131. # btrfs.autoScrub = {
  132. # enable = true;
  133. # interval = "monthly";
  134. # fileSystems = [ "/" ];
  135. # };
  136. #
  137. # # Drive power management and fan control
  138. # hddfancontrol = {
  139. # enable = false;
  140. # settings = {
  141. # harddrives = {
  142. # disks = [
  143. # "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV023WG"
  144. # "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV07RMA"
  145. # "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV020CG"
  146. # ];
  147. # pwmPaths = [
  148. # "/sys/class/hwmon/hwmon5/pwm1:25:10"
  149. # ];
  150. # logVerbosity = "DEBUG";
  151. # };
  152. # };
  153. # };
  154. # Drive spin-down management
  155. # hdparm.devices = [
  156. # {
  157. # device = "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV023WG";
  158. # spindownTime = 120; # 10 minutes
  159. # apmLevel = 127;
  160. # }
  161. # {
  162. # device = "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV07RMA";
  163. # spindownTime = 120;
  164. # apmLevel = 127;
  165. # }
  166. # {
  167. # device = "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV020CG";
  168. # spindownTime = 120;
  169. # apmLevel = 127;
  170. # }
  171. # ];
  172. };
  173. # # Automatic garbage collection
  174. # nix = {
  175. # gc = {
  176. # automatic = true;
  177. # dates = "weekly";
  178. # options = "--delete-older-than 30d";
  179. # };
  180. # optimise.automatic = true;
  181. # };
  182. # # Container runtime
  183. # virtualisation = {
  184. # docker = {
  185. # enable = true;
  186. # storageDriver = "btrfs";
  187. # autoPrune = {
  188. # enable = true;
  189. # dates = "weekly";
  190. # flags = [ "--all" "--force" "--volumes" ];
  191. # };
  192. # };
  193. # };
  194. # System packages
  195. environment.systemPackages = with pkgs; [
  196. # System utilities
  197. htop
  198. btop
  199. iotop
  200. lsof
  201. pciutils
  202. usbutils
  203. # Network tools
  204. curl
  205. wget
  206. rsync
  207. # File system tools
  208. btrfs-progs
  209. xfsprogs
  210. smartmontools
  211. hdparm
  212. # # Container tools
  213. # docker-compose
  214. # Storage management
  215. snapraid
  216. mergerfs
  217. # Monitoring
  218. lm_sensors
  219. nvme-cli
  220. ];
  221. # User configuration
  222. users = {
  223. mutableUsers = false; # Declarative user management
  224. users = {
  225. # Main user account
  226. thomas = {
  227. isNormalUser = true;
  228. extraGroups = [ "wheel" "users" ];
  229. hashedPassword = "$6$jO/t4PtMb4Ky.goy$2diW2qZjswUAVAzRQqOJ7wfGwD9QInJtUfQYEOOp8hkdhAy6wcccYfIG.gEQniStx7ZkxADNQxQ7pyfUiOqll.";
  230. openssh.authorizedKeys.keys = [
  231. "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5o7LT5wPYWgI8Mvr6RKOv+BcsbQgU7PCw2hheVu17alwF1uFUsAYV5BVQu+uv9uEm/UDsCNhfM6TwI0A1prdmtBz4pKiwXbj7fcdp6DcVOgTsPfawbXEpivtJvlhEatyTsR26MjHKnqpT0BxPvj6Ug6pvRkCYW5d2bWXiY9murmAX6Q5kSyNunkB8PdRTH+S47f7eOdCJY63VBOkkiG8M7XyPwFCDTYiHhbMZcejIdY9mB6kYnMQVRHDznQWiQxrcaE1fD/TY3db9GDcOVoo2aDBOZX7WT2+me67sU8dEK9+nSyhWDzBbEs8knu87ZlKPFwhl4slenRniKhbf22OpicXArtEcjEj0GyDJH5e+ZCIQ4eSQanA7TxnKFlDuaf+Qqx55UT+ya4vJJeik7nkzbRHaE9IoWhhiOaOnaN6kHIxuxB6z7EL3Gk7f78+I/qBaj5df6fgnXM3JBXKa5bRH2wqoSetJAo6EGpEgmU2huB1ktiGlO7BlF5XwSw6cb/KT7NSIXhncgLkCzsDVXxecVQv1FnPISBcp3+ti01ADVf2trgpPDbNTWV40Rgiefie0o2fc6KWAFfum1j5N3WWU+XVVmRjDmKKHiEJBLNKDAe0rQf+tryPW4c5GIN7aFoB+8dYFAuUyLd7Fu3vhZdmcckN5ryHunEc0dKPIiuoVZw=="
  232. ];
  233. };
  234. };
  235. };
  236. # # File system mounts for impermanence
  237. # fileSystems = {
  238. # # Boot partition
  239. # "/boot" = {
  240. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-efi";
  241. # fsType = "vfat";
  242. # };
  243. #
  244. # # Root filesystem
  245. # "/" = {
  246. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  247. # fsType = "btrfs";
  248. # options = [ "subvol=@root" "compress=zstd:1" "noatime" ];
  249. # };
  250. #
  251. # # Nix store
  252. # "/nix" = {
  253. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  254. # fsType = "btrfs";
  255. # options = [ "subvol=@nix" "compress=zstd:1" "noatime" ];
  256. # };
  257. #
  258. # # Home directory
  259. # "/home" = {
  260. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  261. # fsType = "btrfs";
  262. # options = [ "subvol=@home" "compress=zstd:1" "noatime" ];
  263. # };
  264. #
  265. # # Persistent data
  266. # "/persist" = {
  267. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  268. # fsType = "btrfs";
  269. # options = [ "subvol=@persist" "compress=zstd:1" "noatime" ];
  270. # neededForBoot = true;
  271. # };
  272. #
  273. # # Logs
  274. # "/logs" = {
  275. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  276. # fsType = "btrfs";
  277. # options = [ "subvol=@logs" "compress=zstd:1" "noatime" ];
  278. # };
  279. #
  280. # # Services data
  281. # "/services" = {
  282. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  283. # fsType = "btrfs";
  284. # options = [ "subvol=@services" "compress=zstd:1" "noatime" ];
  285. # };
  286. #
  287. # # Database storage - nodatacow for performance
  288. # "/databases" = {
  289. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  290. # fsType = "btrfs";
  291. # options = [ "subvol=@databases" "compress=zstd:1" "noatime" "nodatacow" ];
  292. # };
  293. #
  294. # # Cache storage - nodatacow for performance
  295. # "/cache" = {
  296. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  297. # fsType = "btrfs";
  298. # options = [ "subvol=@cache" "compress=zstd:1" "noatime" "nodatacow" ];
  299. # };
  300. #
  301. # # Container storage - nodatacow for performance
  302. # "/containers" = {
  303. # device = lib.mkDefault "/dev/disk/by-partlabel/disk-main-root";
  304. # fsType = "btrfs";
  305. # options = [ "subvol=@containers" "compress=zstd:1" "noatime" "nodatacow" ];
  306. # };
  307. # };
  308. # # Persistent directories for impermanence
  309. # environment.persistence."/persist" = {
  310. # hideMounts = true;
  311. # directories = [
  312. # "/etc/nixos"
  313. # "/etc/ssh"
  314. # "/var/lib/nixos"
  315. # "/var/lib/systemd"
  316. # "/srv"
  317. # ];
  318. # files = [
  319. # "/etc/machine-id"
  320. # ];
  321. # users.thomas = {
  322. # directories = [
  323. # ".ssh"
  324. # ".config"
  325. # ];
  326. # };
  327. # };
  328. # System state version
  329. system.stateVersion = "25.05";
  330. }