forked from lix-project/lix
Updates to nix-reduce-build
Common code in local build package sources refactored out in a function; before building the real set of derivations needed is found (slightly slower for only one build strategy, but less garbage on output and better performance for multiple build strategies). Now you have full choice of best-effort build regardless of method (substituters or actual build), using substituters, building only fixed derivations (should get you all the downloads) and local build without even trying substituters. Some minor fix in the help text about behavior with no package sources.
This commit is contained in:
parent
72f3ea7358
commit
b455c4c45c
|
@ -24,6 +24,9 @@ if test -z "$1" || test "a--help" = "a$1" ; then
|
||||||
echo "derivations with specified output hash (sha256, sha1 or md5)." >&2
|
echo "derivations with specified output hash (sha256, sha1 or md5)." >&2
|
||||||
echo " nix-daemon-substitute:// and nix-self-substitute:// try to substitute" >&2;
|
echo " nix-daemon-substitute:// and nix-self-substitute:// try to substitute" >&2;
|
||||||
echo "maximum amount of paths" >&2;
|
echo "maximum amount of paths" >&2;
|
||||||
|
echo " nix-daemon-build:// and nix-self-build:// try to build (not substitute)" >&2;
|
||||||
|
echo "maximum amount of paths" >&2;
|
||||||
|
echo " If no package sources are specified, required paths are listed." >&2;
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
@ -71,10 +74,37 @@ echo Prepared $(cat wanted-paths | wc -l) paths to get. >&2
|
||||||
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
||||||
echo We need $(cat needed-paths | wc -l) paths. >&2
|
echo We need $(cat needed-paths | wc -l) paths. >&2
|
||||||
|
|
||||||
|
egrep '[.]drv$' derivers-closure > critical-derivers;
|
||||||
|
|
||||||
if test -z "$1" ; then
|
if test -z "$1" ; then
|
||||||
cat needed-paths;
|
cat needed-paths;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
|
refresh_critical_derivers() {
|
||||||
|
echo "Finding needed derivers..." >&2;
|
||||||
|
cat critical-derivers | while read; do
|
||||||
|
if ! (nix-store --query --outputs "$REPLY" | xargs nix-store --check-validity &> /dev/null;); then
|
||||||
|
echo "$REPLY";
|
||||||
|
fi;
|
||||||
|
done > new-critical-derivers;
|
||||||
|
mv new-critical-derivers critical-derivers;
|
||||||
|
echo The needed paths are realized by $(cat critical-derivers | wc -l) derivers. >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
build_here() {
|
||||||
|
cat critical-derivers | while read; do
|
||||||
|
echo "Realising $REPLY using nix-daemon" >&2
|
||||||
|
@bindir@/nix-store -r "${REPLY}"
|
||||||
|
done;
|
||||||
|
}
|
||||||
|
|
||||||
|
try_to_substitute(){
|
||||||
|
cat needed-paths | while read ; do
|
||||||
|
echo "Building $REPLY using nix-daemon" >&2
|
||||||
|
@bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
||||||
|
done;
|
||||||
|
}
|
||||||
|
|
||||||
for i in "$@"; do
|
for i in "$@"; do
|
||||||
sshHost="${i#ssh://}";
|
sshHost="${i#ssh://}";
|
||||||
httpHost="${i#http://}";
|
httpHost="${i#http://}";
|
||||||
|
@ -96,47 +126,41 @@ for i in "$@"; do
|
||||||
gunzip < "$filePath/${REPLY##*/}".nar.gz | nix-store --import;
|
gunzip < "$filePath/${REPLY##*/}".nar.gz | nix-store --import;
|
||||||
done;
|
done;
|
||||||
elif [ "$i" = "nix-daemon://" ] ; then
|
elif [ "$i" = "nix-daemon://" ] ; then
|
||||||
cat needed-paths | while read ; do
|
NIX_REMOTE=daemon try_to_substitute;
|
||||||
echo "Building $REPLY using nix-daemon" >&2
|
refresh_critical_derivers;
|
||||||
NIX_REMOTE=daemon @bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
NIX_REMOTE=daemon build_here;
|
||||||
done;
|
|
||||||
cat derivers-closure | while read; do
|
|
||||||
echo "Realising $REPLY using nix-daemon" >&2
|
|
||||||
NIX_REMOTE=daemon @bindir@/nix-store -r "${REPLY}"
|
|
||||||
done;
|
|
||||||
elif [ "$i" = "nix-self://" ] ; then
|
elif [ "$i" = "nix-self://" ] ; then
|
||||||
cat needed-paths | while read ; do
|
NIX_REMOTE= try_to_substitute;
|
||||||
echo "Building $REPLY using direct Nix build" >&2
|
refresh_critical_derivers;
|
||||||
NIX_REMOTE= @bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
NIX_REMOTE= build_here;
|
||||||
done;
|
|
||||||
cat derivers-closure | while read; do
|
|
||||||
echo "Realising $REPLY using direct Nix build" >&2
|
|
||||||
NIX_REMOTE= @bindir@/nix-store -r "${REPLY}"
|
|
||||||
done;
|
|
||||||
elif [ "$i" = "nix-daemon-fixed://" ] ; then
|
elif [ "$i" = "nix-daemon-fixed://" ] ; then
|
||||||
cat derivers-closure | while read; do
|
refresh_critical_derivers;
|
||||||
|
|
||||||
|
cat critical-derivers | while read; do
|
||||||
if egrep '"(md5|sha1|sha256)"' "$REPLY" &>/dev/null; then
|
if egrep '"(md5|sha1|sha256)"' "$REPLY" &>/dev/null; then
|
||||||
echo "Realising $REPLY using nix-daemon" >&2
|
echo "Realising $REPLY using nix-daemon" >&2
|
||||||
NIX_REMOTE=daemon @bindir@/nix-store -r "${REPLY}"
|
NIX_REMOTE=daemon @bindir@/nix-store -r "${REPLY}"
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
elif [ "$i" = "nix-self-fixed://" ] ; then
|
elif [ "$i" = "nix-self-fixed://" ] ; then
|
||||||
cat derivers-closure | while read; do
|
refresh_critical_derivers;
|
||||||
|
|
||||||
|
cat critical-derivers | while read; do
|
||||||
if egrep '"(md5|sha1|sha256)"' "$REPLY" &>/dev/null; then
|
if egrep '"(md5|sha1|sha256)"' "$REPLY" &>/dev/null; then
|
||||||
echo "Realising $REPLY using direct Nix build" >&2
|
echo "Realising $REPLY using direct Nix build" >&2
|
||||||
NIX_REMOTE= @bindir@/nix-store -r "${REPLY}"
|
NIX_REMOTE= @bindir@/nix-store -r "${REPLY}"
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
elif [ "$i" = "nix-daemon-substitute://" ] ; then
|
elif [ "$i" = "nix-daemon-substitute://" ] ; then
|
||||||
cat needed-paths | while read ; do
|
NIX_REMOTE=daemon try_to_substitute;
|
||||||
echo "Substituting $REPLY using nix-daemon" >&2
|
|
||||||
NIX_REMOTE=daemon @bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
|
||||||
done;
|
|
||||||
elif [ "$i" = "nix-self-substitute://" ] ; then
|
elif [ "$i" = "nix-self-substitute://" ] ; then
|
||||||
cat needed-paths | while read ; do
|
NIX_REMOTE= try_to_substitute;
|
||||||
echo "Substituting $REPLY using direct Nix build" >&2
|
elif [ "$i" = "nix-daemon-build://" ] ; then
|
||||||
NIX_REMOTE= @bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
refresh_critical_derivers;
|
||||||
done;
|
NIX_REMOTE=daemon build_here;
|
||||||
|
elif [ "$i" = "nix-self-build://" ] ; then
|
||||||
|
refresh_critical_derivers;
|
||||||
|
NIX_REMOTE= build_here;
|
||||||
fi;
|
fi;
|
||||||
mv needed-paths wanted-paths;
|
mv needed-paths wanted-paths;
|
||||||
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
||||||
|
|
Loading…
Reference in a new issue