summaryrefslogtreecommitdiff
path: root/modules/nixos/personal/boot.nix
blob: bde1ab0f74b844973e1f4bb68ff5678878b8b5d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
  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";
        };
      })
      (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
          '';
        };
      };
  };
}