lanzaboote/nix/lanzaboote.nix

54 lines
1.8 KiB
Nix
Raw Normal View History

{ lib, config, pkgs, ... }:
2022-11-23 05:59:54 -05:00
with lib;
let
cfg = config.boot.lanzaboote;
2022-11-24 10:59:16 -05:00
sbctlWithPki = pkgs.sbctl.override {
databasePath = "/tmp/pki";
};
2022-11-23 05:59:54 -05:00
in
{
options.boot.lanzaboote = {
enable = mkEnableOption "Enable the LANZABOOTE";
2022-11-24 10:59:16 -05:00
enrollKeys = mkEnableOption "Automatic enrollment of the keys using sbctl";
pkiBundle = mkOption {
type = types.nullOr types.path;
default = null;
description = "PKI bundle containg db, PK, KEK";
};
publicKeyFile = mkOption {
type = types.path;
2022-11-24 10:59:16 -05:00
default = if cfg.pkiBundle != null then "${cfg.pkiBundle}/keys/db/db.pem" else null;
description = "Public key to sign your boot files";
};
privateKeyFile = mkOption {
type = types.path;
2022-11-24 10:59:16 -05:00
default = if cfg.pkiBundle != null then "${cfg.pkiBundle}/keys/db/db.key" else null;
description = "Private key to sign your boot files";
};
package = mkOption {
type = types.package;
default = pkgs.lanzatool;
description = "Lanzatool package";
};
2022-11-23 05:59:54 -05:00
};
config = mkIf cfg.enable {
2022-11-25 19:50:51 -05:00
# bootspec is putting at false
# until we fix this upstream, we will mkForce it.
boot.loader.supportsInitrdSecrets = mkForce true;
2022-11-23 05:59:54 -05:00
boot.loader.external = {
enable = true;
passBootspec = true;
2022-11-24 10:59:16 -05:00
installHook = "${pkgs.writeShellScriptBin "bootinstall" ''
2022-11-25 05:29:56 -05:00
${optionalString cfg.enrollKeys ''
mkdir -p /tmp/pki
cp -r ${cfg.pkiBundle}/* /tmp/pki
${sbctlWithPki}/bin/sbctl enroll-keys --yes-this-might-brick-my-machine
''}
2022-11-24 11:09:51 -05:00
${cfg.package}/bin/lanzatool install --pki-bundle ${cfg.pkiBundle} --public-key ${cfg.publicKeyFile} --private-key ${cfg.privateKeyFile} "$@"
2022-11-24 10:59:16 -05:00
''}/bin/bootinstall";
# ${cfg.package}/bin/lanzatool install ${optionalString cfg.enrollKeys "--auto-enroll"} --pki-bundle ${cfg.pkiBundle}
2022-11-23 05:59:54 -05:00
};
};
}