1 import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "systemd-initrd-luks-tpm2";
4 nodes.machine = { pkgs, ... }: {
7 emptyDiskImages = [ 512 ];
9 # Booting off the TPM2-encrypted device requires an available init script
10 mountHostNixStore = true;
14 boot.loader.systemd-boot.enable = true;
16 boot.initrd.availableKernelModules = [ "tpm_tis" ];
18 environment.systemPackages = with pkgs; [ cryptsetup ];
19 boot.initrd.systemd = {
23 specialisation.boot-luks.configuration = {
24 boot.initrd.luks.devices = lib.mkVMOverride {
27 crypttabExtraOpts = [ "tpm2-device=auto" ];
30 virtualisation.rootDevice = "/dev/mapper/cryptroot";
31 virtualisation.fileSystems."/".autoFormat = true;
36 # Create encrypted volume
37 machine.wait_for_unit("multi-user.target")
38 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdb -")
39 machine.succeed("PASSWORD=supersecret SYSTEMD_LOG_LEVEL=debug systemd-cryptenroll --tpm2-pcrs= --tpm2-device=auto /dev/vdb |& systemd-cat")
41 # Boot from the encrypted disk
42 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf")
43 machine.succeed("sync")
46 # Boot and decrypt the disk
47 machine.wait_for_unit("multi-user.target")
48 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")