1 import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "systemd-initrd-luks-fido2";
4 nodes.machine = { pkgs, config, ... }: {
7 emptyDiskImages = [ 512 ];
9 # Booting off the encrypted disk requires having a Nix store available for the init script
10 mountHostNixStore = true;
12 qemu.options = [ "-device pci-ohci,id=usb-bus" "-device canokey,bus=usb-bus.0,file=/tmp/canokey-file" ];
14 boot.loader.systemd-boot.enable = true;
16 boot.initrd.systemd.enable = true;
18 environment.systemPackages = with pkgs; [ cryptsetup ];
20 specialisation.boot-luks.configuration = {
21 boot.initrd.luks.devices = lib.mkVMOverride {
24 crypttabExtraOpts = [ "fido2-device=auto" ];
27 virtualisation.rootDevice = "/dev/mapper/cryptroot";
28 virtualisation.fileSystems."/".autoFormat = true;
33 # Create encrypted volume
34 machine.wait_for_unit("multi-user.target")
35 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdb -")
36 machine.succeed("PASSWORD=supersecret SYSTEMD_LOG_LEVEL=debug systemd-cryptenroll --fido2-device=auto /dev/vdb |& systemd-cat")
38 # Boot from the encrypted disk
39 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf")
40 machine.succeed("sync")
43 # Boot and decrypt the disk
44 machine.wait_for_unit("multi-user.target")
45 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")