1# Tests the contents attribute of nixos/lib/make-disk-image.nix
2# including its user, group, and mode attributes.
3{
4 system ? builtins.currentSystem,
5 config ? { },
6 pkgs ? import ../.. { inherit system config; },
7}:
8
9with import ../lib/testing-python.nix { inherit system pkgs; };
10with pkgs.lib;
11
12with import common/ec2.nix { inherit makeTest pkgs; };
13
14let
15 config =
16 (import ../lib/eval-config.nix {
17 system = null;
18 modules = [
19 ../modules/testing/test-instrumentation.nix
20 ../modules/profiles/qemu-guest.nix
21 {
22 fileSystems."/".device = "/dev/disk/by-label/nixos";
23 boot.loader.grub.device = "/dev/vda";
24 boot.loader.timeout = 0;
25 nixpkgs.pkgs = pkgs;
26 }
27 ];
28 }).config;
29 image =
30 (import ../lib/make-disk-image.nix {
31 inherit pkgs config;
32 lib = pkgs.lib;
33 format = "qcow2";
34 contents = [
35 {
36 source = pkgs.writeText "testFile" "contents";
37 target = "/testFile";
38 user = "1234";
39 group = "5678";
40 mode = "755";
41 }
42 {
43 source = ./.;
44 target = "/testDir";
45 }
46 ];
47 })
48 + "/nixos.qcow2";
49
50in
51makeEc2Test {
52 name = "image-contents";
53 inherit image;
54 userData = null;
55 script = ''
56 machine.start()
57 # Test that if contents includes a file, it is copied to the target.
58 assert "content" in machine.succeed("cat /testFile")
59 fileDetails = machine.succeed("ls -l /testFile")
60 assert "1234" in fileDetails
61 assert "5678" in fileDetails
62 assert "rwxr-xr-x" in fileDetails
63
64 # Test that if contents includes a directory, it is copied to the target.
65 dirList = machine.succeed("ls /testDir")
66 assert "image-contents.nix" in dirList
67 '';
68}