2020-12-02 18:48:47 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# This do script creates an indirect root to an input flake
|
|
|
|
|
|
|
|
exec >&2
|
|
|
|
|
2020-12-02 23:49:16 +01:00
|
|
|
pfx=${2%.rw}
|
|
|
|
|
2020-12-02 18:48:47 +01:00
|
|
|
redo-ifchange ../flake.nix ../flake.lock || true
|
|
|
|
|
|
|
|
resolve_flake() {
|
2020-12-18 11:48:10 +01:00
|
|
|
STORE_PATH=$(nix flake archive .. --dry-run --json | jq -r .inputs.\"$pfx\".path)
|
2020-12-02 18:48:47 +01:00
|
|
|
|
|
|
|
# Do this after 'info' to avoid unnecessary network activity. nix flake
|
|
|
|
# archive may try to download a flake although the store path is available.
|
|
|
|
if [ ! -d "$STORE_PATH" ]; then
|
2020-12-02 23:49:16 +01:00
|
|
|
nix flake archive --inputs-from .. "$pfx"
|
2020-12-02 18:48:47 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case $2 in
|
|
|
|
# Resolves cleanup targets by their softlinks
|
|
|
|
clean)
|
|
|
|
redo-always || true
|
|
|
|
find . -type l -print -exec realpath -P --relative-base="$PWD" {} \+ |
|
|
|
|
while read p; do
|
|
|
|
if [ "$p" = "${p#/}" ]; then
|
|
|
|
rm -rf -- "$p"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*.rw)
|
|
|
|
resolve_flake "$@"
|
|
|
|
rm -rf -- ".$2"
|
|
|
|
cp --reflink=auto -r --no-preserve=mode "$STORE_PATH" ".$2"
|
|
|
|
ln -sf ".$2" "$3"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
resolve_flake "$@"
|
|
|
|
nix-store -r "$STORE_PATH" --indirect --add-root "$2"
|
|
|
|
[ "$2" = "$3" ] || mv "$2" "$3"
|
|
|
|
;;
|
|
|
|
esac
|