1 # similar to the appliance-repart-image test but with a dm-verity
2 # protected nix store and tmpfs as rootfs
6 name = "appliance-repart-image-verity-store";
8 meta.maintainers = with lib.maintainers; [
21 inherit (config.image.repart.verityStore) partitionIds;
24 imports = [ ../modules/image/repart.nix ];
26 virtualisation.fileSystems = lib.mkVMOverride {
29 options = [ "mode=0755" ];
33 device = "/dev/mapper/usr";
34 # explicitly mount it read-only otherwise systemd-remount-fs will fail
36 fsType = config.image.repart.partitions.${partitionIds.store}.repartConfig.Format;
39 # bind-mount the store
41 device = "/usr/nix/store";
49 # by default the module works with systemd-boot, for simplicity this test directly boots the UKI
50 ukiPath = "/EFI/BOOT/BOOT${lib.toUpper config.nixpkgs.hostPlatform.efiArch}.EFI";
53 name = "appliance-verity-store-image";
56 ${partitionIds.esp} = {
57 # the UKI is injected into this partition by the verityStore module
61 SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M";
64 ${partitionIds.store-verity}.repartConfig = {
67 ${partitionIds.store}.repartConfig = {
74 directBoot.enable = false;
75 mountHostNixStore = false;
80 loader.grub.enable = false;
81 initrd.systemd.enable = true;
85 id = "nixos-appliance";
89 # don't create /usr/bin/env
90 # this would require some extra work on read-only /usr
91 # and it is not a strict necessity
92 system.activationScripts.usrbinenv = lib.mkForce "";
96 { nodes, ... }: # python
102 tmp_disk_image = tempfile.NamedTemporaryFile()
105 "${nodes.machine.virtualisation.qemu.package}/bin/qemu-img",
110 "${nodes.machine.system.build.finalImage}/${nodes.machine.image.repart.imageFile}",
116 os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name
118 machine.wait_for_unit("default.target")
120 with subtest("Running with volatile root"):
121 machine.succeed("findmnt --kernel --type tmpfs /")
123 with subtest("/nix/store is backed by dm-verity protected fs"):
124 verity_info = machine.succeed("dmsetup info --target verity usr")
125 assert "ACTIVE" in verity_info,f"unexpected verity info: {verity_info}"
127 backing_device = machine.succeed("df --output=source /nix/store | tail -n1").strip()
128 assert "/dev/mapper/usr" == backing_device,"unexpected backing device: {backing_device}"