67 lines
2.0 KiB
Nix
Raw Normal View History

2023-12-24 20:09:35 +01:00
{ config, lib, libS, ... }:
let cfg = config.boot;
in {
options = {
boot = {
default = libS.mkOpinionatedOption "enable the boot builder";
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.";
};
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-25 18:54:38 +01:00
fullDiskEncryption = libS.mkOpinionatedOption "use luks full disk encrytion";
2023-12-26 10:45:54 +01:00
useSystemdBoot = libS.mkOpinionatedOption "use systemd boot";
2023-12-24 20:09:35 +01:00
};
};
config.boot = lib.mkIf cfg.default {
2023-12-25 04:27:28 +01:00
initrd = {
# networking for netcard kernelModules = [ "e1000e" ];
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
supportedFilesystems = [ cfg.filesystem ];
2023-12-24 20:09:35 +01:00
tmp.useTmpfs = true;
kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;
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
2023-12-26 03:20:07 +01:00
zfs = lib.mkIf (cfg.filesystem == "zfs") {
2023-12-24 20:09:35 +01:00
enableUnstable = true;
devNodes = "/dev/disk/by-id/";
forceImportRoot = true;
};
2023-12-25 04:27:28 +01:00
2023-12-24 20:09:35 +01:00
loader = {
efi = { canTouchEfiVariables = false; };
2023-12-24 20:09:35 +01:00
generationsDir.copyKernels = true;
2023-12-26 10:45:54 +01:00
systemd-boot.enable = lib.mkIf cfg.useSystemdBoot true;
grub = lib.mkIf (!cfg.useSystemdBoot) {
enable = true;
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
};
};
};
}