static-nix-shell: add $dep/share to XDG_DATA_DIRS, also only add those $dep/bin paths which actually exist to PATH
this actually causes some packages which were previously wrapped to no longer require wrapping (because none of the directories they were adding actually existed)
This commit is contained in:
@@ -76,11 +76,6 @@ in rec {
|
|||||||
# allow any package to be a list of packages, to support things like
|
# allow any package to be a list of packages, to support things like
|
||||||
# -p python3.pkgs.foo.propagatedBuildInputs
|
# -p python3.pkgs.foo.propagatedBuildInputs
|
||||||
pkgsEnv' = lib.flatten pkgsEnv;
|
pkgsEnv' = lib.flatten pkgsEnv;
|
||||||
|
|
||||||
makeWrapperArgs = lib.optionals (pkgsEnv' != []) [
|
|
||||||
"--suffix" "PATH" ":" (lib.makeBinPath pkgsEnv')
|
|
||||||
] ++ extraMakeWrapperArgs;
|
|
||||||
doWrap = makeWrapperArgs != [];
|
|
||||||
in
|
in
|
||||||
stdenv.mkDerivation (final: {
|
stdenv.mkDerivation (final: {
|
||||||
version = "0.1.0"; # default version
|
version = "0.1.0"; # default version
|
||||||
@@ -90,7 +85,7 @@ in rec {
|
|||||||
makeBinaryWrapper
|
makeBinaryWrapper
|
||||||
];
|
];
|
||||||
|
|
||||||
inherit makeWrapperArgs;
|
runtimePrefixes = pkgsEnv';
|
||||||
|
|
||||||
patchPhase = ''
|
patchPhase = ''
|
||||||
substituteInPlace ${srcPath} \
|
substituteInPlace ${srcPath} \
|
||||||
@@ -102,6 +97,7 @@ in rec {
|
|||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
|
|
||||||
mkdir -p $out/bin
|
mkdir -p $out/bin
|
||||||
mv ${srcPath} $out/bin/${srcPath}
|
mv ${srcPath} $out/bin/${srcPath}
|
||||||
|
|
||||||
@@ -109,16 +105,33 @@ in rec {
|
|||||||
echo "$@"
|
echo "$@"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# ensure that all nix-shell references were substituted
|
# ensure that all nix-shell references were substituted
|
||||||
(! grep '#![ \t]*nix-shell' $out/bin/${srcPath}) || die 'not all #!nix-shell directives were processed in ${srcPath}'
|
(! grep '#![ \t]*nix-shell' $out/bin/${srcPath}) || die 'not all #!nix-shell directives were processed in ${srcPath}'
|
||||||
# ensure that there weren't some trailing deps we *didn't* substitute
|
# ensure that there weren't some trailing deps we *didn't* substitute
|
||||||
grep '^# nix deps evaluated statically$' $out/bin/${srcPath} || die 'trailing characters in nix-shell directive for ${srcPath}'
|
grep '^# nix deps evaluated statically$' $out/bin/${srcPath} || die 'trailing characters in nix-shell directive for ${srcPath}'
|
||||||
|
|
||||||
'' + lib.optionalString doWrap ''
|
# wrap the program to place each dependency on PATH and XDG_DATA_DIRS:
|
||||||
# add runtime dependencies to PATH
|
concatTo runtimePrefixesList runtimePrefixes
|
||||||
wrapProgram $out/bin/${srcPath} \
|
extraPaths=
|
||||||
${lib.escapeShellArgs final.makeWrapperArgs}
|
extraXdgDataDirs=
|
||||||
'' + ''
|
for p in "''${runtimePrefixesList[@]}"; do
|
||||||
|
echo "considering if dependency needs to be added to runtime environment(s): $p"
|
||||||
|
# `addToSearchPath` behaves as no-op if the provided path doesn't exist
|
||||||
|
addToSearchPath extraPaths "$p/bin"
|
||||||
|
addToSearchPath extraXdgDataDirs "$p/share"
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$extraPaths" ]; then
|
||||||
|
makeWrapperArgs+=("--suffix" "PATH" ":" "$extraPaths")
|
||||||
|
fi
|
||||||
|
if [ -n "$extraXdgDataDirs" ]; then
|
||||||
|
makeWrapperArgs+=("--suffix" "XDG_DATA_DIRS" ":" "$extraXdgDataDirs")
|
||||||
|
fi
|
||||||
|
if [[ ''${#makeWrapperArgs[@]} != 0 ]]; then
|
||||||
|
wrapProgram $out/bin/${srcPath} \
|
||||||
|
"''${makeWrapperArgs[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
Reference in New Issue
Block a user