| 
									
										
										
										
											2024-03-03 18:06:28 -05:00
										 |  |  | { | 
					
						
							|  |  |  |   config, | 
					
						
							|  |  |  |   lib, | 
					
						
							|  |  |  |   libS, | 
					
						
							| 
									
										
										
										
											2024-10-08 23:39:17 -04:00
										 |  |  |   pkgs, | 
					
						
							| 
									
										
										
										
											2024-03-03 18:06:28 -05:00
										 |  |  |   ... | 
					
						
							|  |  |  | }: | 
					
						
							| 
									
										
										
										
											2023-12-24 20:09:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-03 18:06:28 -05:00
										 |  |  | let | 
					
						
							|  |  |  |   cfg = config.boot; | 
					
						
							|  |  |  | in | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2024-01-02 16:30:08 +01:00
										 |  |  |   options = { | 
					
						
							|  |  |  |     boot = { | 
					
						
							|  |  |  |       default = libS.mkOpinionatedOption "enable the boot builder"; | 
					
						
							| 
									
										
										
										
											2024-05-05 11:44:03 -04:00
										 |  |  |       fullDiskEncryption = libS.mkOpinionatedOption "use luks full disk encryption"; | 
					
						
							| 
									
										
										
										
											2024-02-05 22:45:43 +01:00
										 |  |  |       useSystemdBoot = libS.mkOpinionatedOption "use systemd boot"; | 
					
						
							| 
									
										
										
										
											2023-12-25 03:39:20 +01:00
										 |  |  |       cpuType = lib.mkOption { | 
					
						
							|  |  |  |         type = lib.types.str; | 
					
						
							|  |  |  |         example = "amd"; | 
					
						
							|  |  |  |         default = ""; | 
					
						
							|  |  |  |         description = "The cpu-type installed on the server."; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2024-02-05 22:45:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-25 04:27:28 +01:00
										 |  |  |       amdGPU = libS.mkOpinionatedOption "the system contains a AMD GPU"; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:20:07 +01:00
										 |  |  |       filesystem = lib.mkOption { | 
					
						
							|  |  |  |         type = lib.types.str; | 
					
						
							|  |  |  |         example = "btrfs"; | 
					
						
							| 
									
										
										
										
											2023-12-26 04:07:18 +01:00
										 |  |  |         default = "ext4"; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:20:07 +01:00
										 |  |  |         description = "The filesystem installed."; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2023-12-24 20:09:35 +01:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config.boot = lib.mkIf cfg.default { | 
					
						
							| 
									
										
										
										
											2024-02-05 22:45:43 +01:00
										 |  |  |     supportedFilesystems = [ cfg.filesystem ]; | 
					
						
							|  |  |  |     tmp.useTmpfs = true; | 
					
						
							| 
									
										
										
										
											2025-08-01 00:16:57 -04:00
										 |  |  |     kernelParams = [ | 
					
						
							|  |  |  |       "nordrand" | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  |     ++ lib.optional (cfg.cpuType == "amd") "kvm-amd" | 
					
						
							|  |  |  |     ++ lib.optional cfg.fullDiskEncryption "ip=<ip-addr>::<ip-gateway>:<netmask>"; | 
					
						
							| 
									
										
										
										
											2023-12-25 04:27:28 +01:00
										 |  |  |     initrd = { | 
					
						
							|  |  |  |       kernelModules = lib.mkIf cfg.amdGPU [ "amdgpu" ]; | 
					
						
							| 
									
										
										
										
											2023-12-25 18:54:38 +01:00
										 |  |  |       network = lib.mkIf cfg.fullDiskEncryption { | 
					
						
							| 
									
										
										
										
											2023-12-25 04:27:28 +01:00
										 |  |  |         enable = true; | 
					
						
							| 
									
										
										
										
											2023-12-25 18:54:38 +01:00
										 |  |  |         ssh = { | 
					
						
							|  |  |  |           enable = true; | 
					
						
							|  |  |  |           port = 2222; | 
					
						
							| 
									
										
										
										
											2023-12-25 04:27:28 +01:00
										 |  |  |         }; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 03:20:07 +01:00
										 |  |  |     zfs = lib.mkIf (cfg.filesystem == "zfs") { | 
					
						
							| 
									
										
										
										
											2023-12-24 20:09:35 +01:00
										 |  |  |       devNodes = "/dev/disk/by-id/"; | 
					
						
							|  |  |  |       forceImportRoot = true; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2023-12-25 04:27:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-24 20:09:35 +01:00
										 |  |  |     loader = { | 
					
						
							| 
									
										
										
										
											2024-02-05 22:45:43 +01:00
										 |  |  |       efi.canTouchEfiVariables = false; | 
					
						
							| 
									
										
										
										
											2023-12-24 20:09:35 +01:00
										 |  |  |       generationsDir.copyKernels = true; | 
					
						
							| 
									
										
										
										
											2024-05-05 11:44:03 -04:00
										 |  |  |       systemd-boot = lib.mkIf cfg.useSystemdBoot { | 
					
						
							|  |  |  |         enable = true; | 
					
						
							|  |  |  |         configurationLimit = 10; | 
					
						
							|  |  |  |       }; | 
					
						
							| 
									
										
										
										
											2023-12-26 10:45:54 +01:00
										 |  |  |       grub = lib.mkIf (!cfg.useSystemdBoot) { | 
					
						
							| 
									
										
										
										
											2024-02-06 20:35:02 +01:00
										 |  |  |         enable = lib.mkForce true; | 
					
						
							| 
									
										
										
										
											2023-12-26 10:45:54 +01:00
										 |  |  |         copyKernels = true; | 
					
						
							|  |  |  |         zfsSupport = lib.mkIf (cfg.filesystem == "zfs") true; | 
					
						
							|  |  |  |         efiSupport = true; | 
					
						
							|  |  |  |         efiInstallAsRemovable = true; | 
					
						
							|  |  |  |         fsIdentifier = "uuid"; | 
					
						
							|  |  |  |         enableCryptodisk = lib.mkIf cfg.fullDiskEncryption true; | 
					
						
							| 
									
										
										
										
											2023-12-24 20:09:35 +01:00
										 |  |  |       }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2023-12-25 22:59:17 -05:00
										 |  |  | } |