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 ];
17 # Necessary to boot off the encrypted disk because it requires a init script coming from the Nix store
18 mountHostNixStore = true;
21 boot.loader.systemd-boot.enable = true;
23 environment.systemPackages = with pkgs; [ cryptsetup ];
24 boot.initrd.systemd = {
26 emergencyAccess = true;
29 specialisation.boot-luks.configuration = {
30 boot.initrd.luks.devices = lib.mkVMOverride {
33 keyFile = "/etc/cryptroot.key";
36 virtualisation.rootDevice = "/dev/mapper/cryptroot";
37 virtualisation.fileSystems."/".autoFormat = true;
38 boot.initrd.secrets."/etc/cryptroot.key" = keyfile;
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")
47 # Boot from the encrypted disk
48 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks.conf")
49 machine.succeed("sync")
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")