summaryrefslogtreecommitdiff
path: root/os/core/bootloader.nix
diff options
context:
space:
mode:
authoradikro <adikro@disroot.org>2026-03-01 19:57:16 +0100
committeradikro <adikro@disroot.org>2026-03-01 19:57:16 +0100
commit1be09af058424219de2aad4b9cc27ccf760d23f6 (patch)
treebdc1177b166e1eef36763984b6862d7755a7bde8 /os/core/bootloader.nix
parent4b41ce640c5eddcb50904331e03aac5460caa144 (diff)
...
Diffstat (limited to 'os/core/bootloader.nix')
-rw-r--r--os/core/bootloader.nix44
1 files changed, 41 insertions, 3 deletions
diff --git a/os/core/bootloader.nix b/os/core/bootloader.nix
index dfd9101..aae167e 100644
--- a/os/core/bootloader.nix
+++ b/os/core/bootloader.nix
@@ -1,10 +1,12 @@
{
config,
lib,
+ pkgs,
...
}:
let
cfg = config.os.core.bootloader;
+ gpgHome = "/root/.gnupg";
in
{
options.os.core.bootloader = {
@@ -12,6 +14,7 @@ in
type = lib.types.enum [
"systemd-boot"
"grub"
+ "none"
];
default = "systemd-boot";
description = "Which bootloader to use";
@@ -19,7 +22,7 @@ in
efi = lib.mkOption {
type = lib.types.bool;
- default = true;
+ default = if cfg.grub.device == "nodev" then true else false;
description = "Whether the system uses UEFI or Legacy BIOS";
};
@@ -45,6 +48,13 @@ in
default = 0;
description = "Index of the default boot entry";
};
+ signing = {
+ enable = lib.mkEnableOption "GPG signing for Libreboot/GRUB";
+ keyId = lib.mkOption {
+ type = lib.types.str;
+ description = "The GPG Key ID used to sign the boot files";
+ };
+ };
};
luks.enable = lib.mkEnableOption "LUKS encryption support";
@@ -56,7 +66,7 @@ in
boot = {
loader = {
timeout = cfg.timeout;
- efi.canTouchEfiVariables = cfg.efi;
+ efi.canTouchEfiVariables = lib.mkDefault cfg.efi;
};
supportedFilesystems = [
"ntfs"
@@ -92,10 +102,38 @@ in
efiSupport = cfg.efi;
useOSProber = cfg.grub.useOSProber;
default = cfg.grub.defaultEntry;
-
enableCryptodisk = cfg.luks.enable;
copyKernels = true;
+
+ extraConfig = lib.mkIf cfg.grub.signing.enable ''
+ set check_signatures=enforce
+ terminal_input console
+ terminal_output console
+ '';
+
+ extraInstallCommands = lib.mkIf cfg.grub.signing.enable ''
+ echo "Signing with keys from ${gpgHome}"
+
+ SIGN_CMD="${pkgs.gnupg}/bin/gpg --homedir ${gpgHome} --detach-sign --batch --yes --default-key ${cfg.grub.signing.keyId}"
+
+ $SIGN_CMD /boot/grub/grub.cfg
+
+ for f in /boot/nixos/*; do
+ if [[ "$f" != *.sig ]]; then
+ $SIGN_CMD "$f"
+ fi
+ done
+ '';
};
+ environment.systemPackages = lib.optional cfg.grub.signing.enable pkgs.gnupg;
})
+ {
+ assertions = [
+ {
+ assertion = cfg.grub.signing.enable -> cfg.grub.signing.keyId != "";
+ message = "Bootloader signing is enabled but os.core.bootloader.grub.signing.keyId is not set.";
+ }
+ ];
+ }
];
}