summaryrefslogtreecommitdiff
path: root/sys/boot/secure-boot.nix
blob: 150ff92366f5320d8a978064607a5e44b55b0632 (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
48
49
50
51
52
53
54
55
56
57
58
{
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cfg = config.local.boot.secureBoot;

  pkiBundle =
    if cfg.legacyPath
    then "/etc/secureboot"
    else "/var/lib/sbctl";
in {
  options.local.boot.secureBoot = {
    enable = mkEnableOption "secure boot";

    legacyPath = mkOption {
      type = types.bool;
      default = false;
    };
  };

  config = mkIf cfg.enable {
    assertions = [
      {
        assertion = config.local.boot.efi.enable;
        message = "secure boot requires EFI";
      }
      {
        assertion = config.local.boot.loader == "systemd-boot";
        message = "lanzaboote requires systemd-boot";
      }
    ];

    boot = {
      loader.systemd-boot.enable = mkForce false;

      lanzaboote = {
        enable = true;
        inherit pkiBundle;
      };
    };

    environment.systemPackages = [
      pkgs.sbctl
    ];

    local.boot.impermanence.trust.directories = [
      {
        directory = pkiBundle;
        user = "root";
        group = "root";
        mode = "u=rwx,g=,o=";
      }
    ];
  };
}