|
10 | 10 | willibutz |
11 | 11 | ]; |
12 | 12 |
|
13 | | - nodes.machine = |
14 | | - { |
15 | | - config, |
16 | | - lib, |
17 | | - pkgs, |
18 | | - ... |
19 | | - }: |
| 13 | + defaults = |
| 14 | + { config, lib, ... }: |
20 | 15 | let |
21 | 16 | inherit (config.image.repart.verityStore) partitionIds; |
22 | 17 | in |
23 | 18 | { |
24 | 19 | imports = [ ../modules/image/repart.nix ]; |
25 | 20 |
|
26 | | - virtualisation.fileSystems = lib.mkVMOverride { |
| 21 | + virtualisation.fileSystems = lib.mkVMOverride { }; |
| 22 | + fileSystems = { |
27 | 23 | "/" = { |
28 | 24 | fsType = "tmpfs"; |
29 | 25 | options = [ "mode=0755" ]; |
30 | 26 | }; |
31 | | - |
32 | | - # bind-mount the store |
33 | | - "/nix/store" = { |
34 | | - device = "/usr/nix/store"; |
35 | | - fsType = "none"; |
36 | | - options = [ "bind" ]; |
37 | | - }; |
38 | 27 | }; |
39 | 28 |
|
40 | 29 | image.repart = { |
|
55 | 44 | SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M"; |
56 | 45 | }; |
57 | 46 | }; |
58 | | - ${partitionIds.store-verity}.repartConfig = { |
59 | | - Minimize = "best"; |
60 | | - }; |
61 | | - ${partitionIds.store}.repartConfig = { |
62 | | - Minimize = "best"; |
63 | | - }; |
64 | 47 | }; |
65 | 48 | }; |
66 | 49 |
|
|
75 | 58 | initrd.systemd.enable = true; |
76 | 59 | }; |
77 | 60 |
|
78 | | - system.image = { |
79 | | - id = "nixos-appliance"; |
80 | | - version = "1"; |
81 | | - }; |
| 61 | + system.image.id = "nixos-appliance"; |
82 | 62 |
|
83 | 63 | # don't create /usr/bin/env |
84 | 64 | # this would require some extra work on read-only /usr |
85 | 65 | # and it is not a strict necessity |
86 | 66 | system.activationScripts.usrbinenv = lib.mkForce ""; |
87 | 67 | }; |
88 | 68 |
|
| 69 | + nodes.machine = { |
| 70 | + system.image.version = "1"; |
| 71 | + }; |
| 72 | + |
| 73 | + nodes.without-version = { }; |
| 74 | + |
89 | 75 | testScript = |
90 | 76 | { nodes, ... }: # python |
91 | 77 | '' |
92 | 78 | import os |
93 | 79 | import subprocess |
94 | 80 | import tempfile |
95 | 81 |
|
96 | | - tmp_disk_image = tempfile.NamedTemporaryFile() |
97 | | -
|
98 | | - subprocess.run([ |
| 82 | + def create_disk_image(qemu_img, backing_file): |
| 83 | + tmp = tempfile.NamedTemporaryFile() |
| 84 | + subprocess.run([ |
| 85 | + qemu_img, |
| 86 | + "create", |
| 87 | + "-f", |
| 88 | + "qcow2", |
| 89 | + "-b", |
| 90 | + backing_file, |
| 91 | + "-F", |
| 92 | + "raw", |
| 93 | + tmp.name, |
| 94 | + ], check=True) |
| 95 | + return tmp |
| 96 | +
|
| 97 | + def run_verity_tests(machine): |
| 98 | + with subtest("Running with volatile root"): |
| 99 | + machine.succeed("findmnt --kernel --type tmpfs /") |
| 100 | +
|
| 101 | + with subtest("/nix/store is backed by dm-verity protected fs"): |
| 102 | + verity_info = machine.succeed("dmsetup info --target verity usr") |
| 103 | + assert "ACTIVE" in verity_info, f"unexpected verity info: {verity_info}" |
| 104 | +
|
| 105 | + backing_device = machine.succeed("df --output=source /nix/store | tail -n1").strip() |
| 106 | + assert "/dev/mapper/usr" == backing_device, f"unexpected backing device: {backing_device}" |
| 107 | +
|
| 108 | + tmp_disk_machine = create_disk_image( |
99 | 109 | "${nodes.machine.virtualisation.qemu.package}/bin/qemu-img", |
100 | | - "create", |
101 | | - "-f", |
102 | | - "qcow2", |
103 | | - "-b", |
104 | | - "${nodes.machine.system.build.finalImage}/${nodes.machine.image.repart.imageFile}", |
105 | | - "-F", |
106 | | - "raw", |
107 | | - tmp_disk_image.name, |
108 | | - ]) |
109 | | -
|
110 | | - os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name |
111 | | -
|
| 110 | + "${nodes.machine.system.build.image}/${nodes.machine.image.filePath}", |
| 111 | + ) |
| 112 | + os.environ['NIX_DISK_IMAGE'] = tmp_disk_machine.name |
112 | 113 | machine.wait_for_unit("default.target") |
113 | | -
|
114 | | - with subtest("Running with volatile root"): |
115 | | - machine.succeed("findmnt --kernel --type tmpfs /") |
116 | | -
|
117 | | - with subtest("/nix/store is backed by dm-verity protected fs"): |
118 | | - verity_info = machine.succeed("dmsetup info --target verity usr") |
119 | | - assert "ACTIVE" in verity_info,f"unexpected verity info: {verity_info}" |
120 | | -
|
121 | | - backing_device = machine.succeed("df --output=source /nix/store | tail -n1").strip() |
122 | | - assert "/dev/mapper/usr" == backing_device,"unexpected backing device: {backing_device}" |
| 114 | + run_verity_tests(machine) |
| 115 | + with subtest("Image version is set"): |
| 116 | + machine.succeed("grep IMAGE_VERSION=1 /etc/os-release") |
| 117 | +
|
| 118 | + tmp_disk_without_version = create_disk_image( |
| 119 | + "${nodes."without-version".virtualisation.qemu.package}/bin/qemu-img", |
| 120 | + "${nodes."without-version".system.build.image}/${nodes."without-version".image.filePath}", |
| 121 | + ) |
| 122 | + os.environ['NIX_DISK_IMAGE'] = tmp_disk_without_version.name |
| 123 | + without_version.wait_for_unit("default.target") |
| 124 | + run_verity_tests(without_version) |
| 125 | + with subtest("Image version is not set"): |
| 126 | + without_version.succeed('grep IMAGE_VERSION="" /etc/os-release') |
123 | 127 | ''; |
124 | 128 | } |
0 commit comments