at 23.11-pre 1.6 kB view raw
1import ./make-test-python.nix ({ lib, pkgs, ... }: let 2 3 keyfile = pkgs.writeText "luks-keyfile" '' 4 MIGHAoGBAJ4rGTSo/ldyjQypd0kuS7k2OSsmQYzMH6TNj3nQ/vIUjDn7fqa3slt2 5 gV6EK3TmTbGc4tzC1v4SWx2m+2Bjdtn4Fs4wiBwn1lbRdC6i5ZYCqasTWIntWn+6 6 FllUkMD5oqjOR/YcboxG8Z3B5sJuvTP9llsF+gnuveWih9dpbBr7AgEC 7 ''; 8 9in { 10 name = "systemd-initrd-luks-keyfile"; 11 12 nodes.machine = { pkgs, ... }: { 13 # Use systemd-boot 14 virtualisation = { 15 emptyDiskImages = [ 512 ]; 16 useBootLoader = true; 17 useEFIBoot = true; 18 }; 19 boot.loader.systemd-boot.enable = true; 20 21 environment.systemPackages = with pkgs; [ cryptsetup ]; 22 boot.initrd.systemd = { 23 enable = true; 24 emergencyAccess = true; 25 }; 26 27 specialisation.boot-luks.configuration = { 28 boot.initrd.luks.devices = lib.mkVMOverride { 29 cryptroot = { 30 device = "/dev/vdb"; 31 keyFile = "/etc/cryptroot.key"; 32 }; 33 }; 34 virtualisation.rootDevice = "/dev/mapper/cryptroot"; 35 boot.initrd.secrets."/etc/cryptroot.key" = keyfile; 36 }; 37 }; 38 39 testScript = '' 40 # Create encrypted volume 41 machine.wait_for_unit("multi-user.target") 42 machine.succeed("cryptsetup luksFormat -q --iter-time=1 -d ${keyfile} /dev/vdb") 43 44 # Boot from the encrypted disk 45 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf") 46 machine.succeed("sync") 47 machine.crash() 48 49 # Boot and decrypt the disk 50 machine.wait_for_unit("multi-user.target") 51 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount") 52 ''; 53})