devShellTools.unstructuredDerivationInputEnv: Match passAsFile basename

This commit is contained in:
Robert Hensing 2024-07-05 12:49:55 +02:00
parent 7237aa700f
commit 1cf3103bca
2 changed files with 17 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{
lib,
writeText,
writeTextFile,
}:
let
inherit (builtins) typeOf;
@ -29,7 +29,21 @@ rec {
(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}"
then
let
nameHash = builtins.convertHash {
hash = "sha256:" + builtins.hashString "sha256" name;
toHashFormat = "nix32";
};
basename = ".attr-${nameHash}";
in
lib.nameValuePair "${name}Path" "${
writeTextFile {
name = "shell-passAsFile-${name}";
text = str;
destination = "/${basename}";
}
}/${basename}"
else lib.nameValuePair name str
)
(removeAttrs drvAttrs [

View File

@ -143,9 +143,7 @@ in
diff $exampleBarPathString $barPath
# TODO nice to have, as `cp $barPath foo/` preserves the basename:
# this is usually a mistake, so not that big a deal perhaps
# [[ "$(basename $exampleBarPathString)" = "$(basename $barPath)" ]]
[[ "$(basename $exampleBarPathString)" = "$(basename $barPath)" ]]
)
''${args:+fail "args should not be set by Nix. We don't expect it to and unstructuredDerivationInputEnv removes it."}