74 lines
1.9 KiB
Nix
Raw Normal View History

{
config,
lib,
libS,
...
}:
2023-12-24 20:09:35 +01:00
let
cfg = config.boot;
in
{
options = {
boot = {
default = libS.mkOpinionatedOption "enable the boot builder";
fullDiskEncryption = libS.mkOpinionatedOption "use luks full disk encrytion";
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.";
};
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 {
supportedFilesystems = [ cfg.filesystem ];
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
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 = {
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 = 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
};
};
};
}