1 import ./make-test-python.nix ({ lib, pkgs, ... }: let
3 keyfile = pkgs.writeText "luks-keyfile" ''
4 MIGHAoGBAJ4rGTSo/ldyjQypd0kuS7k2OSsmQYzMH6TNj3nQ/vIUjDn7fqa3slt2
5 gV6EK3TmTbGc4tzC1v4SWx2m+2Bjdtn4Fs4wiBwn1lbRdC6i5ZYCqasTWIntWn+6
6 FllUkMD5oqjOR/YcboxG8Z3B5sJuvTP9llsF+gnuveWih9dpbBr7AgEC
10 name = "systemd-initrd-luks-keyfile";
12 nodes.machine = { pkgs, ... }: {
15 emptyDiskImages = [ 512 ];
19 boot.loader.systemd-boot.enable = true;
21 environment.systemPackages = with pkgs; [ cryptsetup ];
22 boot.initrd.systemd = {
24 emergencyAccess = true;
27 specialisation.boot-luks.configuration = {
28 boot.initrd.luks.devices = lib.mkVMOverride {
31 keyFile = "/etc/cryptroot.key";
34 virtualisation.bootDevice = "/dev/mapper/cryptroot";
35 boot.initrd.secrets."/etc/cryptroot.key" = keyfile;
40 # Create encrypted volume
41 machine.wait_for_unit("multi-user.target")
42 machine.succeed("cryptsetup luksFormat -q --iter-time=1 -d ${keyfile} /dev/vdc")
44 # Boot from the encrypted disk
45 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf")
46 machine.succeed("sync")
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")