aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/dyn-drv/recursive-mod-json.nix
blob: c6a24ca4f3bc3f5feb7a583b0f8d07478d95360f (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
with import ./config.nix;

let innerName = "foo"; in

mkDerivation rec {
  name = "${innerName}.drv";
  SHELL = shell;

  requiredSystemFeatures = [ "recursive-nix" ];

  drv = builtins.unsafeDiscardOutputDependency (import ./text-hashed-output.nix).hello.drvPath;

  buildCommand = ''
    export NIX_CONFIG='experimental-features = nix-command ca-derivations'

    PATH=${builtins.getEnv "EXTRA_PATH"}:$PATH

    # JSON of pre-existing drv
    nix derivation show $drv | jq .[] > drv0.json

    # Fix name
    jq < drv0.json '.name = "${innerName}"' > drv1.json

    # Extend `buildCommand`
    jq < drv1.json '.env.buildCommand += "echo \"I am alive!\" >> $out/hello\n"' > drv0.json

    # Used as our output
    cp $(nix derivation add < drv0.json) $out
  '';
  __contentAddressed = true;
  outputHashMode = "text";
  outputHashAlgo = "sha256";
}