mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 08:53:21 +00:00
33aaac17c5
... and test it.
40 lines
1.4 KiB
Nix
40 lines
1.4 KiB
Nix
{
|
|
lib,
|
|
writeText,
|
|
}:
|
|
let
|
|
inherit (builtins) typeOf;
|
|
in
|
|
rec {
|
|
# This function closely mirrors what this Nix code does:
|
|
# https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1102
|
|
# https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/eval.cc#L1981-L2036
|
|
valueToString = value:
|
|
# We can't just use `toString` on all derivation attributes because that
|
|
# would not put path literals in the closure. So we explicitly copy
|
|
# those into the store here
|
|
if typeOf value == "path" then "${value}"
|
|
else if typeOf value == "list" then toString (map valueToString value)
|
|
else toString value;
|
|
|
|
|
|
# https://github.com/NixOS/nix/blob/2.8.0/src/libstore/build/local-derivation-goal.cc#L992-L1004
|
|
unstructuredDerivationInputEnv = { drvAttrs }:
|
|
# FIXME: this should be `normalAttrs // passAsFileAttrs`
|
|
lib.mapAttrs'
|
|
(name: value:
|
|
let str = valueToString value;
|
|
in if lib.elem name (drvAttrs.passAsFile or [])
|
|
then lib.nameValuePair "${name}Path" "${writeText "pass-as-text-${name}" str}"
|
|
else lib.nameValuePair name str
|
|
)
|
|
drvAttrs;
|
|
|
|
derivationOutputEnv = { outputList, outputMap }:
|
|
# A mapping from output name to the nix store path where they should end up
|
|
# https://github.com/NixOS/nix/blob/2.8.0/src/libexpr/primops.cc#L1253
|
|
lib.genAttrs outputList (output: builtins.unsafeDiscardStringContext outputMap.${output}.outPath);
|
|
|
|
|
|
}
|