default.nix 9.6 KB

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