at 25.11-pre 2.4 kB view raw
1import ./make-test-python.nix ( 2 { lib, pkgs, ... }: 3 { 4 name = "systemd-initrd-luks-password"; 5 6 nodes.machine = 7 { pkgs, ... }: 8 { 9 # Use systemd-boot 10 virtualisation = { 11 emptyDiskImages = [ 12 512 13 512 14 ]; 15 useBootLoader = true; 16 # Booting off the encrypted disk requires an available init script 17 mountHostNixStore = true; 18 useEFIBoot = true; 19 }; 20 boot.loader.systemd-boot.enable = true; 21 22 environment.systemPackages = with pkgs; [ cryptsetup ]; 23 boot.initrd.systemd = { 24 enable = true; 25 emergencyAccess = true; 26 }; 27 28 specialisation.boot-luks.configuration = { 29 boot.initrd.luks.devices = lib.mkVMOverride { 30 # We have two disks and only type one password - key reuse is in place 31 cryptroot.device = "/dev/vdb"; 32 cryptroot2.device = "/dev/vdc"; 33 }; 34 virtualisation.rootDevice = "/dev/mapper/cryptroot"; 35 virtualisation.fileSystems."/".autoFormat = true; 36 # test mounting device unlocked in initrd after switching root 37 virtualisation.fileSystems."/cryptroot2".device = "/dev/mapper/cryptroot2"; 38 }; 39 }; 40 41 testScript = '' 42 # Create encrypted volume 43 machine.wait_for_unit("multi-user.target") 44 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdb -") 45 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdc -") 46 machine.succeed("echo -n supersecret | cryptsetup luksOpen -q /dev/vdc cryptroot2") 47 machine.succeed("mkfs.ext4 /dev/mapper/cryptroot2") 48 49 # Boot from the encrypted disk 50 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf") 51 machine.succeed("sync") 52 machine.crash() 53 54 # Boot and decrypt the disk 55 machine.start() 56 machine.wait_for_console_text("Please enter passphrase for disk cryptroot") 57 machine.send_console("supersecret\n") 58 machine.wait_for_unit("multi-user.target") 59 60 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount"), "/dev/mapper/cryptroot do not appear in mountpoints list" 61 assert "/dev/mapper/cryptroot2 on /cryptroot2 type ext4" in machine.succeed("mount") 62 ''; 63 } 64)