6 inherit (builtins) typeOf;
9 # Docs: doc/build-helpers/dev-shell-tools.chapter.md
10 # Tests: ./tests/default.nix
11 # This function closely mirrors what this Nix code does:
12 # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1102
13 # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/eval.cc#L1981-L2036
14 valueToString = value:
15 # We can't just use `toString` on all derivation attributes because that
16 # would not put path literals in the closure. So we explicitly copy
17 # those into the store here
18 if typeOf value == "path" then "${value}"
19 else if typeOf value == "list" then toString (map valueToString value)
23 # Docs: doc/build-helpers/dev-shell-tools.chapter.md
24 # Tests: ./tests/default.nix
25 # https://github.com/NixOS/nix/blob/2.8.0/src/libstore/build/local-derivation-goal.cc#L992-L1004
26 unstructuredDerivationInputEnv = { drvAttrs }:
27 # FIXME: this should be `normalAttrs // passAsFileAttrs`
30 let str = valueToString value;
31 in if lib.elem name (drvAttrs.passAsFile or [])
35 if builtins?convertHash
36 then builtins.convertHash {
37 hash = "sha256:" + builtins.hashString "sha256" name;
38 toHashFormat = "nix32";
41 builtins.hashString "sha256" name;
42 basename = ".attr-${nameHash}";
44 lib.nameValuePair "${name}Path" "${
46 name = "shell-passAsFile-${name}";
48 destination = "/${basename}";
51 else lib.nameValuePair name str
53 (removeAttrs drvAttrs [
54 # TODO: there may be more of these
58 # Docs: doc/build-helpers/dev-shell-tools.chapter.md
59 # Tests: ./tests/default.nix
60 derivationOutputEnv = { outputList, outputMap }:
61 # A mapping from output name to the nix store path where they should end up
62 # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1253
63 lib.genAttrs outputList (output: builtins.unsafeDiscardStringContext outputMap.${output}.outPath);