2022-11-23 04:59:54 -06:00
|
|
|
{ lib, config, pkgs, ... }:
|
2022-11-23 04:59:54 -06:00
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.boot.lanzaboote;
|
2022-11-24 09:59:16 -06:00
|
|
|
sbctlWithPki = pkgs.sbctl.override {
|
|
|
|
databasePath = "/tmp/pki";
|
|
|
|
};
|
2022-11-23 04:59:54 -06:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.boot.lanzaboote = {
|
|
|
|
enable = mkEnableOption "Enable the LANZABOOTE";
|
2022-11-24 09:59:16 -06:00
|
|
|
enrollKeys = mkEnableOption "Automatic enrollment of the keys using sbctl";
|
2022-11-23 04:59:54 -06:00
|
|
|
pkiBundle = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = "PKI bundle containg db, PK, KEK";
|
|
|
|
};
|
|
|
|
publicKeyFile = mkOption {
|
|
|
|
type = types.path;
|
2022-11-24 09:59:16 -06:00
|
|
|
default = if cfg.pkiBundle != null then "${cfg.pkiBundle}/keys/db/db.pem" else null;
|
2022-11-23 04:59:54 -06:00
|
|
|
description = "Public key to sign your boot files";
|
|
|
|
};
|
|
|
|
privateKeyFile = mkOption {
|
|
|
|
type = types.path;
|
2022-11-24 09:59:16 -06:00
|
|
|
default = if cfg.pkiBundle != null then "${cfg.pkiBundle}/keys/db/db.key" else null;
|
2022-11-23 04:59:54 -06:00
|
|
|
description = "Private key to sign your boot files";
|
|
|
|
};
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.lanzatool;
|
|
|
|
description = "Lanzatool package";
|
|
|
|
};
|
2022-11-23 04:59:54 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
boot.loader.external = {
|
|
|
|
enable = true;
|
2022-11-23 04:59:54 -06:00
|
|
|
passBootspec = true;
|
2022-11-24 09:59:16 -06:00
|
|
|
installHook = "${pkgs.writeShellScriptBin "bootinstall" ''
|
2022-11-25 04:29:56 -06: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 10:09:51 -06:00
|
|
|
${cfg.package}/bin/lanzatool install --pki-bundle ${cfg.pkiBundle} --public-key ${cfg.publicKeyFile} --private-key ${cfg.privateKeyFile} "$@"
|
2022-11-24 09:59:16 -06:00
|
|
|
''}/bin/bootinstall";
|
|
|
|
# ${cfg.package}/bin/lanzatool install ${optionalString cfg.enrollKeys "--auto-enroll"} --pki-bundle ${cfg.pkiBundle}
|
2022-11-23 04:59:54 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|