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;
|
|
|
|
description = "PKI bundle containg db, PK, KEK";
|
|
|
|
};
|
|
|
|
publicKeyFile = mkOption {
|
|
|
|
type = types.path;
|
2022-12-08 14:26:16 -06:00
|
|
|
default = "${cfg.pkiBundle}/keys/db/db.pem";
|
2022-11-23 04:59:54 -06:00
|
|
|
description = "Public key to sign your boot files";
|
|
|
|
};
|
|
|
|
privateKeyFile = mkOption {
|
|
|
|
type = types.path;
|
2022-12-08 14:26:16 -06:00
|
|
|
default = "${cfg.pkiBundle}/keys/db/db.key";
|
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 {
|
2022-12-17 17:31:09 -06:00
|
|
|
boot.bootspec = {
|
|
|
|
enable = true;
|
|
|
|
extensions."lanzaboote"."osRelease" = config.environment.etc."os-release".source;
|
|
|
|
};
|
|
|
|
boot.loader.supportsInitrdSecrets = true;
|
2022-11-23 04:59:54 -06:00
|
|
|
boot.loader.external = {
|
|
|
|
enable = true;
|
2022-11-26 15:23:00 -06:00
|
|
|
installHook = pkgs.writeShellScript "bootinstall" ''
|
|
|
|
${optionalString cfg.enrollKeys ''
|
|
|
|
mkdir -p /tmp/pki
|
|
|
|
cp -r ${cfg.pkiBundle}/* /tmp/pki
|
|
|
|
${sbctlWithPki}/bin/sbctl enroll-keys --yes-this-might-brick-my-machine
|
|
|
|
''}
|
|
|
|
|
|
|
|
${cfg.package}/bin/lanzatool install \
|
|
|
|
--public-key ${cfg.publicKeyFile} \
|
|
|
|
--private-key ${cfg.privateKeyFile} \
|
|
|
|
${config.boot.loader.efi.efiSysMountPoint} \
|
|
|
|
/nix/var/nix/profiles/system-*-link
|
|
|
|
'';
|
2022-11-23 04:59:54 -06:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|