Fetch flake once, use store path for later calls

This commit is contained in:
clerie 2024-04-07 19:48:27 +02:00
parent ce4221f4bb
commit 221052d846
2 changed files with 6 additions and 3 deletions

8
bij.sh
View File

@ -43,6 +43,8 @@ if [[ -z ${FLAKE} ]]; then
FLAKE="$(pwd)" FLAKE="$(pwd)"
fi fi
FLAKE_STORE_PATH="$(nix flake archive --json "${FLAKE}" | jq -r .path)"
if [[ "${#ARGS[@]}" -lt 1 ]]; then if [[ "${#ARGS[@]}" -lt 1 ]]; then
echo "Command not specified" echo "Command not specified"
exit 1 exit 1
@ -62,15 +64,15 @@ HOST="${ARGS[1]}"
if [[ -z ${TARGET} ]]; then if [[ -z ${TARGET} ]]; then
# Use fqdn as target # Use fqdn as target
TARGET="$(nix --extra-experimental-features "nix-command flakes" eval --raw "${FLAKE}#nixosConfigurations.${HOST}" --apply "host: host.config.networking.fqdn")" TARGET="$(nix --extra-experimental-features "nix-command flakes" eval --raw "${FLAKE_STORE_PATH}#nixosConfigurations.${HOST}" --apply "host: host.config.networking.fqdn")"
fi fi
case "${COMMAND}" in case "${COMMAND}" in
apply) apply)
nixos-rebuild switch --flake "${FLAKE}#${HOST}" --target-host "${TARGET}" --use-substitutes --use-remote-sudo nixos-rebuild switch --flake "${FLAKE_STORE_PATH}#${HOST}" --target-host "${TARGET}" --use-substitutes --use-remote-sudo
;; ;;
build) build)
nixos-rebuild build --flake "${FLAKE}#${HOST}" nixos-rebuild build --flake "${FLAKE_STORE_PATH}#${HOST}"
;; ;;
exec) exec)
# shellcheck disable=SC2029 # shellcheck disable=SC2029

View File

@ -12,6 +12,7 @@
name = "bij"; name = "bij";
text = builtins.readFile ./bij.sh; text = builtins.readFile ./bij.sh;
runtimeInputs = with pkgs; [ runtimeInputs = with pkgs; [
jq
]; ];
}; };
default = bij; default = bij;