diff options
| author | aristote <quentin.aristote@irif.fr> | 2025-02-28 16:32:21 +0100 |
|---|---|---|
| committer | aristote <quentin.aristote@irif.fr> | 2025-02-28 16:51:20 +0100 |
| commit | 1c53bf43d1e752cc76e0aac74ac6460a200bc0f6 (patch) | |
| tree | 50f947e3f5b92e59eda400d6e9b47b5d4f02cdd8 /modules/nixos/personal/boot.nix | |
| parent | 2f864beb9c0910d36c386571a89fff227d43cd34 (diff) | |
nixos: unattended decrypt: switch to initrd key
Diffstat (limited to 'modules/nixos/personal/boot.nix')
| -rw-r--r-- | modules/nixos/personal/boot.nix | 51 |
1 files changed, 36 insertions, 15 deletions
diff --git a/modules/nixos/personal/boot.nix b/modules/nixos/personal/boot.nix index 9486d5e..149d9b9 100644 --- a/modules/nixos/personal/boot.nix +++ b/modules/nixos/personal/boot.nix @@ -1,23 +1,44 @@ -{ config, lib, ... }: - -let cfg = config.personal.boot; +{ + config, + lib, + ... +}: let + cfg = config.personal.boot; in { options.personal.boot = { grub.enable = lib.mkEnableOption "grub"; efi.enable = lib.mkEnableOption "EFI"; + unattendedReboot = lib.mkEnableOption "unattended reboots"; }; - config.boot.loader = lib.mkMerge [ - (lib.mkIf cfg.grub.enable { - grub = { - enable = true; - enableCryptodisk = config.boot.initrd.luks.devices != { }; - device = lib.mkDefault "nodev"; + config.boot = { + loader = lib.mkMerge [ + (lib.mkIf cfg.grub.enable { + grub = { + enable = true; + enableCryptodisk = config.boot.initrd.luks.devices != {}; + device = lib.mkDefault "nodev"; + }; + }) + (lib.mkIf cfg.efi.enable { + efi.canTouchEfiVariables = true; + grub.efiSupport = true; + }) + ]; + + initrd = let + crypt = config.personal.hardware.disks.crypted; + in + lib.mkIf (cfg.unattendedReboot && crypt != null) { + secrets."/keyfile.luks" = /etc/luks/keys/tmp; + luks.devices.crypt = { + fallbackToPassword = true; + keyFile = "/keyfile.luks"; + postOpenCommands = '' + echo "Disabling temporary LUKS key file..." + cryptsetup --verbose luksRemoveKey ${crypt} /keyfile.luks + ''; + }; }; - }) - (lib.mkIf cfg.efi.enable { - efi.canTouchEfiVariables = true; - grub.efiSupport = true; - }) - ]; + }; } |
