Make some apply defaults optional

This commit is contained in:
clerie 2024-08-08 20:46:16 +02:00
parent 221052d846
commit a1430c542e
2 changed files with 35 additions and 1 deletions

View File

@ -23,6 +23,12 @@ Normally the flake of the current working directory is used. But you can specify
bij --flake /etc/nixos apply astatine 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. Sometimes it is required to execute some commands on a host directly.
``` ```

30
bij.sh
View File

@ -4,6 +4,8 @@ set -euo pipefail
FLAKE= FLAKE=
TARGET= TARGET=
USE_SUBSTITUTES="1"
USE_REMOTE_SUDO="1"
ARGS=() ARGS=()
OPTS=() OPTS=()
@ -20,6 +22,22 @@ while [[ $# -gt 0 ]]; do
shift shift
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 shift
OPTS=( "$@" ) 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")" TARGET="$(nix --extra-experimental-features "nix-command flakes" eval --raw "${FLAKE_STORE_PATH}#nixosConfigurations.${HOST}" --apply "host: host.config.networking.fqdn")"
fi 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 case "${COMMAND}" in
apply) 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) build)
nixos-rebuild build --flake "${FLAKE_STORE_PATH}#${HOST}" nixos-rebuild build --flake "${FLAKE_STORE_PATH}#${HOST}"