at 24.11-pre 1.8 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 # Necessary to boot off the encrypted disk because it requires a init script coming from the Nix store 18 mountHostNixStore = true; 19 useEFIBoot = true; 20 }; 21 boot.loader.systemd-boot.enable = true; 22 23 environment.systemPackages = with pkgs; [ cryptsetup ]; 24 boot.initrd.systemd = { 25 enable = true; 26 emergencyAccess = true; 27 }; 28 29 specialisation.boot-luks.configuration = { 30 boot.initrd.luks.devices = lib.mkVMOverride { 31 cryptroot = { 32 device = "/dev/vdb"; 33 keyFile = "/etc/cryptroot.key"; 34 }; 35 }; 36 virtualisation.rootDevice = "/dev/mapper/cryptroot"; 37 virtualisation.fileSystems."/".autoFormat = true; 38 boot.initrd.secrets."/etc/cryptroot.key" = keyfile; 39 }; 40 }; 41 42 testScript = '' 43 # Create encrypted volume 44 machine.wait_for_unit("multi-user.target") 45 machine.succeed("cryptsetup luksFormat -q --iter-time=1 -d ${keyfile} /dev/vdb") 46 47 # Boot from the encrypted disk 48 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf") 49 machine.succeed("sync") 50 machine.crash() 51 52 # Boot and decrypt the disk 53 machine.wait_for_unit("multi-user.target") 54 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount") 55 ''; 56})