at 25.11-pre 1.8 kB view raw
1import ./make-test-python.nix ( 2 { lib, pkgs, ... }: 3 { 4 name = "systemd-initrd-luks-tpm2"; 5 6 nodes.machine = 7 { pkgs, ... }: 8 { 9 # Use systemd-boot 10 virtualisation = { 11 emptyDiskImages = [ 512 ]; 12 useBootLoader = true; 13 # Booting off the TPM2-encrypted device requires an available init script 14 mountHostNixStore = true; 15 useEFIBoot = true; 16 tpm.enable = true; 17 }; 18 boot.loader.systemd-boot.enable = true; 19 20 boot.initrd.availableKernelModules = [ "tpm_tis" ]; 21 22 environment.systemPackages = with pkgs; [ cryptsetup ]; 23 boot.initrd.systemd = { 24 enable = true; 25 }; 26 27 specialisation.boot-luks.configuration = { 28 boot.initrd.luks.devices = lib.mkVMOverride { 29 cryptroot = { 30 device = "/dev/vdb"; 31 crypttabExtraOpts = [ "tpm2-device=auto" ]; 32 }; 33 }; 34 virtualisation.rootDevice = "/dev/mapper/cryptroot"; 35 virtualisation.fileSystems."/".autoFormat = true; 36 }; 37 }; 38 39 testScript = '' 40 # Create encrypted volume 41 machine.wait_for_unit("multi-user.target") 42 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdb -") 43 machine.succeed("PASSWORD=supersecret SYSTEMD_LOG_LEVEL=debug systemd-cryptenroll --tpm2-pcrs= --tpm2-device=auto /dev/vdb |& systemd-cat") 44 45 # Boot from the encrypted disk 46 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf") 47 machine.succeed("sync") 48 machine.crash() 49 50 # Boot and decrypt the disk 51 machine.wait_for_unit("multi-user.target") 52 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount") 53 ''; 54 } 55)