at 23.11-pre 2.2 kB view raw
1import ./make-test-python.nix ({ lib, pkgs, ... }: { 2 name = "luks"; 3 4 nodes.machine = { pkgs, ... }: { 5 # Use systemd-boot 6 virtualisation = { 7 emptyDiskImages = [ 512 512 ]; 8 useBootLoader = true; 9 useEFIBoot = true; 10 }; 11 boot.loader.systemd-boot.enable = true; 12 13 boot.kernelParams = lib.mkOverride 5 [ "console=tty1" ]; 14 15 environment.systemPackages = with pkgs; [ cryptsetup ]; 16 17 specialisation = rec { 18 boot-luks.configuration = { 19 boot.initrd.luks.devices = lib.mkVMOverride { 20 # We have two disks and only type one password - key reuse is in place 21 cryptroot.device = "/dev/vdb"; 22 cryptroot2.device = "/dev/vdc"; 23 }; 24 virtualisation.rootDevice = "/dev/mapper/cryptroot"; 25 }; 26 boot-luks-custom-keymap.configuration = lib.mkMerge [ 27 boot-luks.configuration 28 { 29 console.keyMap = "neo"; 30 } 31 ]; 32 }; 33 }; 34 35 enableOCR = true; 36 37 testScript = '' 38 # Create encrypted volume 39 machine.wait_for_unit("multi-user.target") 40 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdb -") 41 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdc -") 42 43 # Boot from the encrypted disk 44 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf") 45 machine.succeed("sync") 46 machine.crash() 47 48 # Boot and decrypt the disk 49 machine.start() 50 machine.wait_for_text("Passphrase for") 51 machine.send_chars("supersecret\n") 52 machine.wait_for_unit("multi-user.target") 53 54 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount") 55 56 # Boot from the encrypted disk with custom keymap 57 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks-custom-keymap.conf") 58 machine.succeed("sync") 59 machine.crash() 60 61 # Boot and decrypt the disk 62 machine.start() 63 machine.wait_for_text("Passphrase for") 64 machine.send_chars("havfkhfrkfl\n") 65 machine.wait_for_unit("multi-user.target") 66 67 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount") 68 ''; 69})