aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/lang/eval-okay-context-introspection.nix
blob: 8886cf32e94b7af469de06412d96d45e9d7ee3a1 (plain)
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
let
  drv = derivation {
    name = "fail";
    builder = "/bin/false";
    system = "x86_64-linux";
    outputs = [ "out" "foo" ];
  };

  path = "${./eval-okay-context-introspection.nix}";

  desired-context = {
    "${builtins.unsafeDiscardStringContext path}" = {
      path = true;
    };
    "${builtins.unsafeDiscardStringContext drv.drvPath}" = {
      outputs = [ "foo" "out" ];
      allOutputs = true;
    };
  };

  combo-path = "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}";
  legit-context = builtins.getContext combo-path;

  reconstructed-path = builtins.appendContext
    (builtins.unsafeDiscardStringContext combo-path)
    desired-context;

  # Eta rule for strings with context.
  etaRule = str:
    str == builtins.appendContext
      (builtins.unsafeDiscardStringContext str)
      (builtins.getContext str);

  # Only holds true if string context contains both a `DrvDeep` and
  # `Opaque` element.
  almostEtaRule = str:
    str == builtins.addDrvOutputDependencies
      (builtins.unsafeDiscardOutputDependency str);

  addDrvOutputDependencies_idempotent = str:
    builtins.addDrvOutputDependencies str ==
    builtins.addDrvOutputDependencies (builtins.addDrvOutputDependencies str);

  rules = str: [
    (etaRule str)
    (almostEtaRule str)
    (addDrvOutputDependencies_idempotent str)
  ];

in [
  (legit-context == desired-context)
  (reconstructed-path == combo-path)
  (etaRule "foo")
  (etaRule drv.foo.outPath)
] ++ builtins.concatMap rules [
  drv.drvPath
  (builtins.addDrvOutputDependencies drv.drvPath)
  (builtins.unsafeDiscardOutputDependency drv.drvPath)
]