1import ./make-test-python.nix ({ lib, pkgs, ... }: {
2 name = "luks";
3
4 nodes.machine = { pkgs, ... }: {
5 imports = [ ./common/auto-format-root-device.nix ];
6
7 # Use systemd-boot
8 virtualisation = {
9 emptyDiskImages = [ 512 512 ];
10 useBootLoader = true;
11 useEFIBoot = true;
12 # To boot off the encrypted disk, we need to have a init script which comes from the Nix store
13 mountHostNixStore = true;
14 };
15 boot.loader.systemd-boot.enable = true;
16
17 boot.kernelParams = lib.mkOverride 5 [ "console=tty1" ];
18
19 environment.systemPackages = with pkgs; [ cryptsetup ];
20
21 specialisation = rec {
22 boot-luks.configuration = {
23 boot.initrd.luks.devices = lib.mkVMOverride {
24 # We have two disks and only type one password - key reuse is in place
25 cryptroot.device = "/dev/vdb";
26 cryptroot2.device = "/dev/vdc";
27 };
28 virtualisation.rootDevice = "/dev/mapper/cryptroot";
29 };
30 boot-luks-custom-keymap.configuration = lib.mkMerge [
31 boot-luks.configuration
32 {
33 console.keyMap = "neo";
34 }
35 ];
36 };
37 };
38
39 enableOCR = true;
40
41 testScript = ''
42 # Create encrypted volume
43 machine.wait_for_unit("multi-user.target")
44 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdb -")
45 machine.succeed("echo -n supersecret | cryptsetup luksFormat -q --iter-time=1 /dev/vdc -")
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.start()
54 machine.wait_for_text("Passphrase for")
55 machine.send_chars("supersecret\n")
56 machine.wait_for_unit("multi-user.target")
57
58 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")
59
60 # Boot from the encrypted disk with custom keymap
61 machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-luks-custom-keymap.conf")
62 machine.succeed("sync")
63 machine.crash()
64
65 # Boot and decrypt the disk
66 machine.start()
67 machine.wait_for_text("Passphrase for")
68 machine.send_chars("havfkhfrkfl\n")
69 machine.wait_for_unit("multi-user.target")
70
71 assert "/dev/mapper/cryptroot on / type ext4" in machine.succeed("mount")
72 '';
73})