linkIntoOwnPackage: refactor
This commit is contained in:
@@ -38,9 +38,6 @@
|
||||
linkIntoOwnPackage = pkg: path: { wantMan ? null, ...}@args: let
|
||||
paths = if lib.isList path then path else [ path ];
|
||||
suffix = (lib.head paths) + (if paths != [ path ] then "-and-other-paths" else "");
|
||||
bin = lib.getBin pkg;
|
||||
man = lib.getMan pkg;
|
||||
out = pkg;
|
||||
wantMan' = if wantMan == null then
|
||||
builtins.any (p: lib.hasPrefix "share/man" p || lib.hasPrefix "share/doc" p) paths
|
||||
else
|
||||
@@ -48,30 +45,55 @@
|
||||
in
|
||||
runCommandLocalOverridable "${pkg.pname or pkg.name}-${suffix}" ({
|
||||
outputs = [ "out" ] ++ lib.optionals wantMan' [ "man" ];
|
||||
inputs = pkg.all;
|
||||
pathsToLink = paths;
|
||||
configurePhase = ''
|
||||
runHook preConfigure
|
||||
|
||||
# all vars supplied by nix are str, so convert -> array
|
||||
concatTo pathsToLink pathsToLink
|
||||
concatTo pathsToLink_ pathsToLink
|
||||
pathsToLink=("''${pathsToLink_[@]}")
|
||||
unset pathsToLink_
|
||||
concatTo inputs_ inputs
|
||||
inputs=("''${inputs_[@]}")
|
||||
unset inputs_
|
||||
|
||||
runHook postConfigure
|
||||
'';
|
||||
fixupPhase = ''
|
||||
runHook preFixup
|
||||
|
||||
# move man-related outputs to man output
|
||||
# TODO: doesn't nix do this for us automatically?
|
||||
for item in share/doc share/man; do
|
||||
if [ -e "$item" ]; then
|
||||
moveToOutput "$item" "$man"
|
||||
fi
|
||||
done
|
||||
|
||||
runHook postFixup
|
||||
'';
|
||||
} // args) ''
|
||||
tryLink() {
|
||||
local srcPath="$1/$2"
|
||||
local dirName=$(dirname "$2")
|
||||
test -e "$srcPath" && mkdir -p "$out/$dirName" && ln -s "$srcPath" "$out/$2"
|
||||
local input=$1
|
||||
local relPath=$2
|
||||
local srcPath="$input/$relPath"
|
||||
local dirName=$(dirname "$relPath")
|
||||
test -e "$srcPath" && mkdir -p "$out/$dirName" && ln -s "$srcPath" "$out/$relPath"
|
||||
}
|
||||
tryLinkFromAnyInput() {
|
||||
local item=$1
|
||||
local linked=
|
||||
for toplevel in "''${inputs[@]}"; do
|
||||
if tryLink "$toplevel" "$item"; then
|
||||
linked=1
|
||||
fi
|
||||
done
|
||||
test -n "$linked" || echo "failed to link $item" >&2
|
||||
}
|
||||
for item in "''${pathsToLink[@]}"; do
|
||||
tryLink "${bin}" "$item" ||
|
||||
tryLink "${man}" "$item" ||
|
||||
tryLink "${out}" "$item" ||
|
||||
echo "failed to link $item" >&2
|
||||
done
|
||||
|
||||
for item in share/doc share/man; do
|
||||
if [ -e "$item" ]; then
|
||||
moveToOutput "$item" "$man"
|
||||
fi
|
||||
for item in "''${pathsToLink[@]}"; do
|
||||
tryLinkFromAnyInput "$item"
|
||||
done
|
||||
'';
|
||||
|
||||
|
Reference in New Issue
Block a user