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