1
0

default.nix 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. { inputs, outputs, pkgs, lib, config, ... }:
  2. {
  3. imports = [
  4. inputs.nixos-facter-modules.nixosModules.facter
  5. { config.facter.reportPath = ./facter.json; }
  6. outputs.modules.global.nix-config
  7. # inputs.impermanence.nixosModules.impermanence
  8. inputs.disko.nixosModules.disko
  9. ./disko.nix
  10. # ./secrets.nix
  11. # ./services
  12. ];
  13. # System identification
  14. networking.hostName = "odin";
  15. networking.useDHCP = lib.mkDefault true;
  16. # Boot configuration
  17. boot = {
  18. # Use systemd-boot for UEFI systems
  19. loader = {
  20. systemd-boot.enable = true;
  21. efi.canTouchEfiVariables = true;
  22. grub.devices = [ config.disko.devices.disk.main.device ];
  23. timeout = 3;
  24. };
  25. # Kernel parameters for server workload
  26. kernelParams = [ "rootflags=compress=zstd:1,noatime" ];
  27. kernelModules = [ "nct6775" ];
  28. # Enable KSM for memory efficiency with containers
  29. kernel.sysctl = {
  30. "kernel.sysrq" = 1;
  31. "vm.swappiness" = 10;
  32. "net.core.default_qdisc" = "cake";
  33. };
  34. };
  35. # # Impermanence: reset root on boot
  36. # initrd.postDeviceCommands = lib.mkAfter ''
  37. # # Get device from disko config
  38. # DEVICE=/dev/disk/by-id/nvme-KINGSTON_SNV3S1000G_50026B7383CC0908-part2
  39. #
  40. # mkdir -p /mnt
  41. # mount -o subvol=/ $DEVICE /mnt
  42. #
  43. # # Create a directory for old roots if it doesn't exist
  44. # mkdir -p /mnt/old-roots
  45. #
  46. # # Move current root to old-roots with timestamp if it exists
  47. # if [[ -e /mnt/@root && ! -e /mnt/@root-blank ]]; then
  48. # timestamp=$(date --date="@$(stat -c %Y /mnt/@root)" "+%Y-%m-%d_%H:%M:%S")
  49. # mv /mnt/@root "/mnt/old-roots/@root-$timestamp"
  50. # fi
  51. #
  52. # # Function to recursively delete subvolumes
  53. # delete_subvolume_recursively() {
  54. # for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
  55. # delete_subvolume_recursively "/mnt/$i"
  56. # done
  57. # btrfs subvolume delete "$1"
  58. # }
  59. #
  60. # # Delete old roots older than 30 days
  61. # for i in $(find /mnt/old-roots/ -maxdepth 1 -mtime +30); do
  62. # delete_subvolume_recursively "$i"
  63. # done
  64. #
  65. # # Create fresh root from blank if needed or create blank if it doesn't exist
  66. # if [[ -e /mnt/@root-blank ]]; then
  67. # btrfs subvolume delete /mnt/@root || true
  68. # btrfs subvolume snapshot /mnt/@root-blank /mnt/@root
  69. # else
  70. # btrfs subvolume create /mnt/@root-blank
  71. # btrfs subvolume create /mnt/@root
  72. # fi
  73. #
  74. # umount /mnt
  75. # '';
  76. # };
  77. hardware = {
  78. fancontrol = {
  79. enable = true;
  80. config = ''
  81. INTERVAL=10
  82. DEVPATH=hwmon1=devices/pci0000:00/0000:00:02.2/0000:04:00.0/nvme/nvme0 hwmon2=devices/platform/nct6775.656
  83. DEVNAME=hwmon1=nvme hwmon2=nct6798
  84. FCTEMPS=hwmon2/pwm7=hwmon1/temp1_input hwmon2/pwm2=hwmon1/temp1_input
  85. FCFANS=hwmon2/pwm7=hwmon2/fan7_input hwmon2/pwm2=hwmon2/fan2_input
  86. MINTEMP=hwmon2/pwm7=30 hwmon2/pwm2=30
  87. MAXTEMP=hwmon2/pwm7=60 hwmon2/pwm2=60
  88. MINSTART=hwmon2/pwm7=95 hwmon2/pwm2=150
  89. MINSTOP=hwmon2/pwm7=75 hwmon2/pwm2=0
  90. '';
  91. };
  92. };
  93. # Services configuration
  94. services = {
  95. # Drive power management and fan control
  96. hddfancontrol = {
  97. enable = true;
  98. settings = {
  99. harddrives =
  100. let
  101. devices = config.disko.devices.disk;
  102. in
  103. {
  104. disks = [
  105. devices.storage1.device
  106. devices.storage2.device
  107. devices.storage3.device
  108. ];
  109. pwmPaths = [
  110. "/sys/class/hwmon/hwmon2/pwm1:20:0"
  111. "/sys/class/hwmon/hwmon2/pwm4:80:60"
  112. ];
  113. logVerbosity = "DEBUG";
  114. extraArgs = [
  115. "--min-fan-speed-prct=0"
  116. ];
  117. };
  118. };
  119. };
  120. # SSH configuration is managed in secrets.nix
  121. openssh = {
  122. enable = true;
  123. openFirewall = true;
  124. settings = {
  125. PasswordAuthentication = false;
  126. PermitRootLogin = "no";
  127. X11Forwarding = false;
  128. };
  129. # hostKeys = [ ];
  130. };
  131. # System monitoring
  132. # smartd = {
  133. # enable = true;
  134. # autodetect = true;
  135. # notifications.mail.enable = false; # Configure if you want email alerts
  136. # };
  137. # # Time synchronization
  138. # timesyncd.enable = true;
  139. #
  140. # # Btrfs maintenance
  141. # btrfs.autoScrub = {
  142. # enable = true;
  143. # interval = "monthly";
  144. # fileSystems = [ "/" ];
  145. # };
  146. # Drive spin-down management
  147. # hdparm.devices = [
  148. # {
  149. # device = "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV023WG";
  150. # spindownTime = 120; # 10 minutes
  151. # apmLevel = 127;
  152. # }
  153. # {
  154. # device = "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV07RMA";
  155. # spindownTime = 120;
  156. # apmLevel = 127;
  157. # }
  158. # {
  159. # device = "/dev/disk/by-id/ata-ST8000VN002-2ZM188_WPV020CG";
  160. # spindownTime = 120;
  161. # apmLevel = 127;
  162. # }
  163. # ];
  164. };
  165. # # Automatic garbage collection
  166. # nix = {
  167. # gc = {
  168. # automatic = true;
  169. # dates = "weekly";
  170. # options = "--delete-older-than 30d";
  171. # };
  172. # optimise.automatic = true;
  173. # };
  174. # # Container runtime
  175. # virtualisation = {
  176. # docker = {
  177. # enable = true;
  178. # storageDriver = "btrfs";
  179. # autoPrune = {
  180. # enable = true;
  181. # dates = "weekly";
  182. # flags = [ "--all" "--force" "--volumes" ];
  183. # };
  184. # };
  185. # };
  186. # System packages
  187. environment.systemPackages = with pkgs; [
  188. # System utilities
  189. htop
  190. btop
  191. iotop
  192. lsof
  193. pciutils
  194. usbutils
  195. # Network tools
  196. curl
  197. wget
  198. rsync
  199. # File system tools
  200. btrfs-progs
  201. xfsprogs
  202. smartmontools
  203. hdparm
  204. # # Container tools
  205. # docker-compose
  206. # Storage management
  207. snapraid
  208. mergerfs
  209. # Monitoring
  210. lm_sensors
  211. nvme-cli
  212. ];
  213. # User configuration
  214. users = {
  215. mutableUsers = false; # Declarative user management
  216. users = {
  217. # Main user account
  218. thomas = {
  219. isNormalUser = true;
  220. extraGroups = [ "wheel" "users" ];
  221. hashedPassword = "$6$jO/t4PtMb4Ky.goy$2diW2qZjswUAVAzRQqOJ7wfGwD9QInJtUfQYEOOp8hkdhAy6wcccYfIG.gEQniStx7ZkxADNQxQ7pyfUiOqll.";
  222. openssh.authorizedKeys.keys = [
  223. "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC5o7LT5wPYWgI8Mvr6RKOv+BcsbQgU7PCw2hheVu17alwF1uFUsAYV5BVQu+uv9uEm/UDsCNhfM6TwI0A1prdmtBz4pKiwXbj7fcdp6DcVOgTsPfawbXEpivtJvlhEatyTsR26MjHKnqpT0BxPvj6Ug6pvRkCYW5d2bWXiY9murmAX6Q5kSyNunkB8PdRTH+S47f7eOdCJY63VBOkkiG8M7XyPwFCDTYiHhbMZcejIdY9mB6kYnMQVRHDznQWiQxrcaE1fD/TY3db9GDcOVoo2aDBOZX7WT2+me67sU8dEK9+nSyhWDzBbEs8knu87ZlKPFwhl4slenRniKhbf22OpicXArtEcjEj0GyDJH5e+ZCIQ4eSQanA7TxnKFlDuaf+Qqx55UT+ya4vJJeik7nkzbRHaE9IoWhhiOaOnaN6kHIxuxB6z7EL3Gk7f78+I/qBaj5df6fgnXM3JBXKa5bRH2wqoSetJAo6EGpEgmU2huB1ktiGlO7BlF5XwSw6cb/KT7NSIXhncgLkCzsDVXxecVQv1FnPISBcp3+ti01ADVf2trgpPDbNTWV40Rgiefie0o2fc6KWAFfum1j5N3WWU+XVVmRjDmKKHiEJBLNKDAe0rQf+tryPW4c5GIN7aFoB+8dYFAuUyLd7Fu3vhZdmcckN5ryHunEc0dKPIiuoVZw=="
  224. ];
  225. };
  226. };
  227. };
  228. # # Persistent directories for impermanence
  229. # environment.persistence."/persist" = {
  230. # hideMounts = true;
  231. # directories = [
  232. # "/etc/nixos"
  233. # "/etc/ssh"
  234. # "/var/lib/nixos"
  235. # "/var/lib/systemd"
  236. # "/srv"
  237. # ];
  238. # files = [
  239. # "/etc/machine-id"
  240. # ];
  241. # users.thomas = {
  242. # directories = [
  243. # ".ssh"
  244. # ".config"
  245. # ];
  246. # };
  247. # };
  248. # System state version
  249. system.stateVersion = "25.05";
  250. }