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 useEFIBoot = true;
10 qemu.package = lib.mkForce (pkgs.qemu_test.override { canokeySupport = true; });
11 qemu.options = [ "-device canokey,file=/tmp/canokey-file" ];
12 };
13 boot.loader.systemd-boot.enable = true;
14
15 boot.initrd.systemd.enable = true;
16
17 environment.systemPackages = with pkgs; [ cryptsetup ];
18
19 specialisation.boot-luks.configuration = {
20 boot.initrd.luks.devices = lib.mkVMOverride {
21 cryptroot = {
22 device = "/dev/vdc";
23 crypttabExtraOpts = [ "fido2-device=auto" ];
24 };
25 };
26 virtualisation.bootDevice = "/dev/mapper/cryptroot";
27 };
28 };
29
30 testScript = ''
31 # Create encrypted volume
32 machine.wait_for_unit("multi-user.target")
33 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdc -")
34 machine.succeed("PASSWORD=supersecret SYSTEMD_LOG_LEVEL=debug systemd-cryptenroll --fido2-device=auto /dev/vdc |& systemd-cat")
35
36 # Boot from the encrypted disk
37 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf")
38 machine.succeed("sync")
39 machine.crash()
40
41 # Boot and decrypt the disk
42 machine.wait_for_unit("multi-user.target")
43 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")
44 '';
45})