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