about summary refs log tree commit diff
path: root/nixos/tests/nix/misc.nix
blob: 6a22ffe0d901fb520e4374421aba632c6c04e2a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Miscellaneous small tests that don't warrant their own VM run.
{ pkgs, ... }:

let
  inherit (pkgs) lib;
  tests = {
    default = testsForPackage { nixPackage = pkgs.nix; };
    lix = testsForPackage { nixPackage = pkgs.lix; };
  };

  testsForPackage = args: lib.recurseIntoAttrs {
    # If the attribute is not named 'test'
    # You will break all the universe on the release-*.nix side of things.
    # `discoverTests` relies on `test` existence to perform a `callTest`.
    test = testMiscFeatures args;
    passthru.override = args': testsForPackage (args // args');
  };

  testMiscFeatures = { nixPackage, ... }: pkgs.testers.nixosTest (
  let
    foo = pkgs.writeText "foo" "Hello World";
  in {
    name = "${nixPackage.pname}-misc";
    meta.maintainers = with lib.maintainers; [ raitobezarius artturin ];

    nodes.machine =
      { lib, ... }:
      {
        system.extraDependencies = [ foo ];

        nix.package = nixPackage;
      };

    testScript =
      ''
        import json

        def get_path_info(path):
            result = machine.succeed(f"nix --option experimental-features nix-command path-info --json {path}")
            parsed = json.loads(result)
            return parsed

        with subtest("nix-db"):
            out = "${foo}"
            info = get_path_info(out)
            print(info)

            pathinfo = info[0] if isinstance(info, list) else info[out]

            if (
                pathinfo["narHash"]
                != "sha256-BdMdnb/0eWy3EddjE83rdgzWWpQjfWPAj3zDIFMD3Ck="
            ):
                raise Exception("narHash not set")

            if pathinfo["narSize"] != 128:
                raise Exception("narSize not set")

        with subtest("nix-db"):
            machine.succeed("nix-store -qR /run/current-system | grep nixos-")
      '';
  });
  in
  tests