2024-06-24 15:38:28 +00:00
|
|
|
# Configuration options specific to bootloader management.
|
|
|
|
# SecureBoot is handled via Lanzaboote. See https://github.com/nix-community/lanzaboote
|
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2024-12-06 18:04:47 +00:00
|
|
|
namespace,
|
2024-06-24 15:38:28 +00:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
# Bootloader
|
|
|
|
let
|
2024-12-06 18:04:47 +00:00
|
|
|
cfg = config.${namespace}.bootloader;
|
2024-06-24 15:38:28 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
2024-12-06 18:04:47 +00:00
|
|
|
${namespace}.bootloader = {
|
2024-06-24 15:38:28 +00:00
|
|
|
enable = lib.mkOption {
|
|
|
|
description = "Automatically configures the bootloader. Set to false to configure manually.";
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
|
|
|
|
2024-09-08 15:58:56 +00:00
|
|
|
secureboot.enable = lib.mkEnableOption "Enables Secureboot support (please read the README before enabling!).";
|
|
|
|
tpm2.enable = lib.mkEnableOption "Enables TPM2 support.";
|
2024-06-24 15:38:28 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable (
|
|
|
|
lib.mkMerge [
|
|
|
|
(lib.mkIf cfg.secureboot.enable {
|
|
|
|
boot = {
|
|
|
|
# Enable Secure Boot
|
|
|
|
bootspec.enable = true;
|
|
|
|
|
|
|
|
# Use Lanzaboote in place of systemd-boot.
|
2024-09-08 15:58:56 +00:00
|
|
|
loader = {
|
|
|
|
systemd-boot.enable = false;
|
|
|
|
efi.canTouchEfiVariables = true;
|
|
|
|
};
|
2024-06-24 15:38:28 +00:00
|
|
|
lanzaboote = {
|
|
|
|
enable = true;
|
|
|
|
pkiBundle = "/etc/secureboot";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
2024-07-13 17:34:59 +00:00
|
|
|
# Set up TPM if enabled. See https://wiki.nixos.org/wiki/TPM
|
2024-06-24 15:38:28 +00:00
|
|
|
(lib.mkIf (cfg.tpm2.enable) {
|
2024-06-24 17:08:18 +00:00
|
|
|
boot.initrd = {
|
2024-09-08 15:58:56 +00:00
|
|
|
# Enable modules and support for TPM auto-unlocking
|
2024-06-24 17:08:18 +00:00
|
|
|
systemd.enable = true;
|
|
|
|
availableKernelModules = [ "tpm_crb" ];
|
|
|
|
kernelModules = [ "tpm_crb" ];
|
|
|
|
};
|
2024-06-24 15:38:28 +00:00
|
|
|
# After installing and rebooting, set it up via https://wiki.archlinux.org/title/Systemd-cryptenroll#Trusted_Platform_Module
|
|
|
|
environment.systemPackages = with pkgs; [ tpm2-tss ];
|
|
|
|
security.tpm2 = {
|
|
|
|
enable = true;
|
|
|
|
pkcs11.enable = true;
|
|
|
|
tctiEnvironment.enable = true;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
|
|
|
|
# Use the default systemd-boot bootloader.
|
|
|
|
(lib.mkIf (!cfg.secureboot.enable) {
|
|
|
|
boot.loader = {
|
|
|
|
systemd-boot.enable = true;
|
|
|
|
efi.canTouchEfiVariables = true;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|