From a1430c542eb46e5cffb9d7121387d67d729357ac Mon Sep 17 00:00:00 2001 From: clerie Date: Thu, 8 Aug 2024 20:46:16 +0200 Subject: [PATCH] Make some apply defaults optional --- README.md | 6 ++++++ bij.sh | 30 +++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b30925f..b6be1da 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ Normally the flake of the current working directory is used. But you can specify bij --flake /etc/nixos apply astatine ``` +Change some defaults if they don't fit. + +``` +bij apply astatine --no-use-remote-sudo --no-use-substitutes +``` + Sometimes it is required to execute some commands on a host directly. ``` diff --git a/bij.sh b/bij.sh index 8c5b100..1b0349c 100755 --- a/bij.sh +++ b/bij.sh @@ -4,6 +4,8 @@ set -euo pipefail FLAKE= TARGET= +USE_SUBSTITUTES="1" +USE_REMOTE_SUDO="1" ARGS=() OPTS=() @@ -20,6 +22,22 @@ while [[ $# -gt 0 ]]; do shift shift ;; + --use-substitutes) + USE_SUBSTITUTES="1" + shift + ;; + --no-use-substitutes) + USE_SUBSTITUTES="" + shift + ;; + --use-remote-sudo) + USE_REMOTE_SUDO="1" + shift + ;; + --no-use-remote-sudo) + USE_REMOTE_SUDO="" + shift + ;; --) shift OPTS=( "$@" ) @@ -67,9 +85,19 @@ if [[ -z ${TARGET} ]]; then TARGET="$(nix --extra-experimental-features "nix-command flakes" eval --raw "${FLAKE_STORE_PATH}#nixosConfigurations.${HOST}" --apply "host: host.config.networking.fqdn")" fi +APPLY_OPTS=() + +if [[ -n "${USE_SUBSTITUTES}" ]]; then + APPLY_OPTS+=("--use-substitutes") +fi + +if [[ -n "${USE_REMOTE_SUDO}" ]]; then + APPLY_OPTS+=("--use-remote-sudo") +fi + case "${COMMAND}" in apply) - nixos-rebuild switch --flake "${FLAKE_STORE_PATH}#${HOST}" --target-host "${TARGET}" --use-substitutes --use-remote-sudo + nixos-rebuild switch --flake "${FLAKE_STORE_PATH}#${HOST}" --target-host "${TARGET}" "${APPLY_OPTS[@]}" ;; build) nixos-rebuild build --flake "${FLAKE_STORE_PATH}#${HOST}"