2008-02-27 23:26:47 +02:00
|
|
|
#! @shell@
|
|
|
|
|
|
|
|
WORKING_DIRECTORY=$(mktemp -d "${TMPDIR:-/tmp}"/nix-reduce-build-XXXXXX);
|
|
|
|
cd "$WORKING_DIRECTORY";
|
|
|
|
|
2008-06-12 20:45:38 +03:00
|
|
|
if test -z "$1" || test "a--help" = "a$1" ; then
|
|
|
|
echo 'nix-reduce-build (paths or Nix expressions) -- (package sources)' >&2
|
2008-02-27 23:26:47 +02:00
|
|
|
echo As in: >&2
|
2008-06-12 20:45:38 +03:00
|
|
|
echo nix-reduce-build /etc/nixos/nixos -- ssh://user@somewhere.nowhere.example.org >&2
|
|
|
|
echo nix-reduce-build /etc/nixos/nixos -- \\
|
|
|
|
echo " " \''http://somewhere.nowhere.example.org/nix/nix-http-export.cgi?needed_path='\' >&2
|
|
|
|
echo " store path name will be added into the end of the URL" >&2
|
|
|
|
echo nix-reduce-build /etc/nixos/nixos -- file://home/user/nar/ >&2
|
|
|
|
echo " that should be a directory where gzipped 'nix-store --export' ">&2
|
|
|
|
echo " files are located (they should have .nar.gz extension)" >&2
|
|
|
|
echo " Or all together: " >&2
|
|
|
|
echo -e nix-reduce-build /expr.nix /e2.nix -- \\\\\\\n\
|
|
|
|
" ssh://a@b.example.com http://n.example.com/get-nar?q= file://nar/" >&2
|
2008-06-14 11:30:35 +03:00
|
|
|
echo " Also supports best-effort local builds of failing expression set:" >&2
|
|
|
|
echo "nix-reduce-build /e.nix -- nix-daemon:// nix-self://" >&2
|
|
|
|
echo " nix-daemon:// builds using daemon"
|
|
|
|
echo " nix-self:// builds directly using nix-store from current installation" >&2
|
2008-02-27 23:26:47 +02:00
|
|
|
exit;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
while ! test "$1" = "--" || test "$1" = "" ; do
|
|
|
|
echo "$1" >> initial; >&2
|
|
|
|
shift;
|
|
|
|
done
|
|
|
|
shift;
|
|
|
|
echo Will work on $(cat initial | wc -l) targets. >&2
|
|
|
|
|
|
|
|
while read ; do
|
|
|
|
case "$REPLY" in
|
2008-06-14 11:30:35 +03:00
|
|
|
${NIX_STORE_DIR:-/nix/store}/*)
|
2008-02-27 23:26:47 +02:00
|
|
|
echo "$REPLY" >> paths; >&2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
nix-instantiate "$REPLY" >> paths;
|
|
|
|
;;
|
|
|
|
esac;
|
|
|
|
done < initial;
|
|
|
|
echo Proceeding $(cat paths | wc -l) paths. >&2
|
|
|
|
|
|
|
|
while read; do
|
|
|
|
case "$REPLY" in
|
|
|
|
*.drv)
|
|
|
|
echo "$REPLY" >> derivers; >&2
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
nix-store --query --deriver "$REPLY" >>derivers;
|
|
|
|
;;
|
|
|
|
esac;
|
|
|
|
done < paths;
|
|
|
|
echo Found $(cat derivers | wc -l) derivers. >&2
|
|
|
|
|
|
|
|
cat derivers | xargs nix-store --query -R > derivers-closure;
|
|
|
|
echo Proceeding at most $(cat derivers-closure | wc -l) derivers. >&2
|
|
|
|
|
|
|
|
cat derivers-closure | egrep '[.]drv$' | xargs nix-store --query --outputs > wanted-paths;
|
|
|
|
cat derivers-closure | egrep -v '[.]drv$' >> wanted-paths;
|
|
|
|
echo Prepared $(cat wanted-paths | wc -l) paths to get. >&2
|
|
|
|
|
|
|
|
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
|
|
|
echo We need $(cat needed-paths | wc -l) paths. >&2
|
|
|
|
|
|
|
|
if test -z "$1" ; then
|
|
|
|
cat needed-paths;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
for i in "$@"; do
|
2008-04-29 07:03:54 +03:00
|
|
|
sshHost="${i#ssh://}";
|
|
|
|
httpHost="${i#http://}";
|
|
|
|
httpsHost="${i#https://}";
|
2008-05-11 18:54:30 +03:00
|
|
|
filePath="${i#file:/}";
|
2008-04-29 07:03:54 +03:00
|
|
|
if [ "$i" != "$sshHost" ]; then
|
|
|
|
cat needed-paths | while read; do
|
2008-06-12 20:45:38 +03:00
|
|
|
echo "Getting $REPLY and its closure over ssh" >&2
|
2008-04-29 07:03:54 +03:00
|
|
|
nix-copy-closure --from "$sshHost" --gzip "$REPLY" </dev/null || true;
|
|
|
|
done;
|
|
|
|
elif [ "$i" != "$httpHost" ] || [ "$i" != "$httpsHost" ]; then
|
|
|
|
cat needed-paths | while read; do
|
2008-06-12 20:45:38 +03:00
|
|
|
echo "Getting $REPLY over http/https" >&2
|
2008-05-07 17:18:28 +03:00
|
|
|
curl ${BAD_CERTIFICATE:+-k} -L "$i${REPLY##*/}" | gunzip | nix-store --import;
|
2008-04-29 07:03:54 +03:00
|
|
|
done;
|
2008-06-14 11:30:35 +03:00
|
|
|
elif [ "$i" != "$filePath" ] ; then
|
2008-05-11 18:54:30 +03:00
|
|
|
cat needed-paths | while read; do
|
2008-06-12 20:45:38 +03:00
|
|
|
echo "Installing $REPLY from file" >&2
|
2008-05-11 18:54:30 +03:00
|
|
|
gunzip < "$filePath/${REPLY##*/}".nar.gz | nix-store --import;
|
|
|
|
done;
|
2008-06-14 11:30:35 +03:00
|
|
|
elif [ "$i" = "nix-daemon://" ] ; then
|
|
|
|
cat needed-paths | while read ; do
|
|
|
|
echo "Building $REPLY using nix-daemon" >&2
|
|
|
|
NIX_REMOTE=daemon @bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
|
|
|
done;
|
2008-06-14 11:48:40 +03:00
|
|
|
cat derivers-closure | while read; do
|
|
|
|
echo "Realising $REPLY using nix-daemon" >&2
|
|
|
|
NIX_REMOTE=daemon @bindir@/nix-store -r "${REPLY}"
|
|
|
|
done;
|
2008-06-14 11:30:35 +03:00
|
|
|
elif [ "$i" = "nix-self://" ] ; then
|
|
|
|
cat needed-paths | while read ; do
|
|
|
|
echo "Building $REPLY using direct Nix build" >&2
|
2008-06-14 11:48:40 +03:00
|
|
|
NIX_REMOTE= @bindir@/nix-store -r "${NIX_STORE_DIR:-/nix/store}/${REPLY##*/}"
|
|
|
|
done;
|
|
|
|
cat derivers-closure | while read; do
|
|
|
|
echo "Realising $REPLY using direct Nix build" >&2
|
|
|
|
NIX_REMOTE= @bindir@/nix-store -r "${REPLY}"
|
2008-06-14 11:30:35 +03:00
|
|
|
done;
|
2008-04-29 07:03:54 +03:00
|
|
|
fi;
|
2008-02-27 23:26:47 +02:00
|
|
|
mv needed-paths wanted-paths;
|
|
|
|
cat wanted-paths | xargs nix-store --check-validity --print-invalid > needed-paths;
|
|
|
|
echo We still need $(cat needed-paths | wc -l) paths. >&2
|
|
|
|
done;
|
|
|
|
|
|
|
|
cd /
|
|
|
|
rm -r "$WORKING_DIRECTORY"
|