generated from meterriblecrew/flake-template
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
#!/bin/sh |
|
# This do script creates an indirect root to an input flake |
|
|
|
exec >&2 |
|
|
|
pfx=${2%.rw} |
|
|
|
redo-ifchange ../flake.nix ../flake.lock || true |
|
|
|
resolve_flake() { |
|
STORE_PATH=$(nix flake info --json --inputs-from .. "$pfx" | jq -r .path) |
|
|
|
# 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 |
|
nix flake archive --inputs-from .. "$pfx" |
|
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
|
|
|