nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at haskell-updates 58 lines 1.9 kB view raw
1{ 2 lib, 3 writeText, 4}: 5let 6 inherit (builtins) typeOf; 7in 8rec { 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 = 15 value: 16 # We can't just use `toString` on all derivation attributes because that 17 # would not put path literals in the closure. So we explicitly copy 18 # those into the store here 19 if typeOf value == "path" then 20 "${value}" 21 else if typeOf value == "list" then 22 toString (map valueToString value) 23 else 24 toString value; 25 26 # Docs: doc/build-helpers/dev-shell-tools.chapter.md 27 # Tests: ./tests/default.nix 28 # https://github.com/NixOS/nix/blob/2.8.0/src/libstore/build/local-derivation-goal.cc#L992-L1004 29 unstructuredDerivationInputEnv = 30 { drvAttrs }: 31 # FIXME: this should be `normalAttrs // passAsFileAttrs` 32 lib.mapAttrs' 33 ( 34 name: value: 35 let 36 str = valueToString value; 37 in 38 if lib.elem name (drvAttrs.passAsFile or [ ]) then 39 lib.nameValuePair "${name}Path" "${writeText "shell-passAsFile-${name}" str}" 40 else 41 lib.nameValuePair name str 42 ) 43 ( 44 removeAttrs drvAttrs [ 45 # TODO: there may be more of these 46 "args" 47 ] 48 ); 49 50 # Docs: doc/build-helpers/dev-shell-tools.chapter.md 51 # Tests: ./tests/default.nix 52 derivationOutputEnv = 53 { outputList, outputMap }: 54 # A mapping from output name to the nix store path where they should end up 55 # https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1253 56 lib.genAttrs outputList (output: builtins.unsafeDiscardStringContext outputMap.${output}.outPath); 57 58}