1 { system ? builtins.currentSystem
3 , pkgs ? import ../.. {inherit system config; }
4 , systemdStage1 ? false }:
5 import ./make-test-python.nix ({ lib, pkgs, ... }: let
7 keyfile = pkgs.writeText "luks-keyfile" ''
8 MIGHAoGBAJ4rGTSo/ldyjQypd0kuS7k2OSsmQYzMH6TNj3nQ/vIUjDn7fqa3slt2
9 gV6EK3TmTbGc4tzC1v4SWx2m+2Bjdtn4Fs4wiBwn1lbRdC6i5ZYCqasTWIntWn+6
10 FllUkMD5oqjOR/YcboxG8Z3B5sJuvTP9llsF+gnuveWih9dpbBr7AgEC
14 name = "initrd-luks-empty-passphrase";
16 nodes.machine = { pkgs, ... }: {
17 imports = lib.optionals (!systemdStage1) [ ./common/auto-format-root-device.nix ];
20 emptyDiskImages = [ 512 ];
23 # This requires to have access
24 # to a host Nix store as
25 # the new root device is /dev/vdb
26 # an empty 512MiB drive, containing no Nix store.
27 mountHostNixStore = true;
28 fileSystems."/".autoFormat = lib.mkIf systemdStage1 true;
31 boot.loader.systemd-boot.enable = true;
32 boot.initrd.systemd = lib.mkIf systemdStage1 {
34 emergencyAccess = true;
36 environment.systemPackages = with pkgs; [ cryptsetup ];
38 specialisation.boot-luks-wrong-keyfile.configuration = {
39 boot.initrd.luks.devices = lib.mkVMOverride {
42 keyFile = "/etc/cryptroot.key";
43 tryEmptyPassphrase = true;
44 fallbackToPassword = !systemdStage1;
47 virtualisation.rootDevice = "/dev/mapper/cryptroot";
48 boot.initrd.secrets."/etc/cryptroot.key" = keyfile;
51 specialisation.boot-luks-missing-keyfile.configuration = {
52 boot.initrd.luks.devices = lib.mkVMOverride {
55 keyFile = "/etc/cryptroot.key";
56 tryEmptyPassphrase = true;
57 fallbackToPassword = !systemdStage1;
60 virtualisation.rootDevice = "/dev/mapper/cryptroot";
65 # Encrypt key with empty key so boot should try keyfile and then fallback to empty passphrase
68 def grub_select_boot_luks_wrong_key_file():
70 Selects "boot-luks" from the GRUB menu
71 to trigger a login request.
73 machine.send_monitor_command("sendkey down")
74 machine.send_monitor_command("sendkey down")
75 machine.send_monitor_command("sendkey ret")
77 def grub_select_boot_luks_missing_key_file():
79 Selects "boot-luks" from the GRUB menu
80 to trigger a login request.
82 machine.send_monitor_command("sendkey down")
83 machine.send_monitor_command("sendkey ret")
85 # Create encrypted volume
86 machine.wait_for_unit("multi-user.target")
87 machine.succeed("echo "" | cryptsetup luksFormat /dev/vdb --batch-mode")
88 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks-wrong-keyfile.conf")
89 machine.succeed("sync")
92 # Check if rootfs is on /dev/mapper/cryptroot
93 machine.wait_for_unit("multi-user.target")
94 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")
96 # Choose boot-luks-missing-keyfile specialisation
97 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks-missing-keyfile.conf")
98 machine.succeed("sync")
101 # Check if rootfs is on /dev/mapper/cryptroot
102 machine.wait_for_unit("multi-user.target")
103 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")