From 597a100bb2b4ce193c582996cf3c39540cb7cfed Mon Sep 17 00:00:00 2001 From: sid Date: Sun, 10 May 2026 15:50:04 +0200 Subject: [PATCH 1/2] rebuild: remove dix and nom --- apps/rebuild/default.nix | 4 ---- apps/rebuild/rebuild.sh | 26 +++++++++++--------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/rebuild/default.nix b/apps/rebuild/default.nix index 72503a3..21242c7 100644 --- a/apps/rebuild/default.nix +++ b/apps/rebuild/default.nix @@ -7,8 +7,6 @@ hostname, nix, nixos-rebuild-ng, - nix-output-monitor, - dix, ... }: @@ -28,7 +26,5 @@ writeShellApplication { hostname nix nixos-rebuild-ng - nix-output-monitor - dix ]; } diff --git a/apps/rebuild/rebuild.sh b/apps/rebuild/rebuild.sh index cb78314..177a35b 100755 --- a/apps/rebuild/rebuild.sh +++ b/apps/rebuild/rebuild.sh @@ -48,7 +48,6 @@ Rebuild_nixos() { # Construct rebuild command local CMD=("nixos-rebuild" "switch" "--sudo") - [[ -n "$TARGET_HOST" || -n "$BUILD_HOST" ]] && CMD+=("--ask-sudo-password") CMD+=("--flake" "$FLAKE") [ "$ROLLBACK" = 1 ] && CMD+=("--rollback") [ "$SHOW_TRACE" = 1 ] && CMD+=("--show-trace") @@ -58,6 +57,7 @@ Rebuild_nixos() { _status "Using '$TARGET_HOST' as target host." fi [ -n "$TARGET_HOST" ] && CMD+=("--target-host" "$TARGET_HOST") + [[ -n "$TARGET_HOST" || -n "$BUILD_HOST" ]] && CMD+=("--ask-sudo-password") # Build config first so we can diff it local BUILD_CMD=("nixos-rebuild" "build" "--flake" "$FLAKE") @@ -67,18 +67,16 @@ Rebuild_nixos() { if [ "$ROLLBACK" = 0 ]; then _status "Building NixOS configuration '$FLAKE'..." _status "Executing command: ${BUILD_CMD[*]}" - "${BUILD_CMD[@]}" |&nom || error "NixOS build failed" - _status "Package diff:" - dix /run/current-system result - rm result + "${BUILD_CMD[@]}" || error "NixOS build failed" + + _status "Switching to new NixOS configuration" else - _status "Rolling back to last NixOS generation..." + _status "Rolling back to last NixOS generation" fi - _status "Switching to new NixOS configuration" sudo -v _status "Executing command: ${CMD[*]}" - "${CMD[@]}" |& nom || error "NixOS rebuild failed" + "${CMD[@]}" || error "NixOS rebuild failed" success "NixOS rebuild completed successfully." } @@ -107,17 +105,15 @@ Rebuild_home() { [ "$SHOW_TRACE" = 1 ] && BUILD_CMD+=("--show-trace") _status "Building Home Manager configuration '$FLAKE'..." _status "Executing command: ${BUILD_CMD[*]}" - "${BUILD_CMD[@]}" |& nom || error "Home Manager build failed" - _status "Package diff:" - dix /run/current-system result - rm result + "${BUILD_CMD[@]}" || error "Home Manager build failed" + + _status "Switching to new Home Manager configuration" else - _status "Rolling back to last Home Manager generation..." + _status "Rolling back to last Home Manager generation" fi - _status "Switching to new Home Manager configuration" _status "Executing command: ${CMD[*]}" - "${CMD[@]}" |& nom || error "Home Manager rebuild failed" + "${CMD[@]}" || error "Home Manager rebuild failed" success "Home Manager rebuild completed successfully." } From 9a659b458030a205d1cf4910c4075fb98c5162a2 Mon Sep 17 00:00:00 2001 From: sid Date: Sun, 10 May 2026 16:34:32 +0200 Subject: [PATCH 2/2] rebuild: add env var support --- apps/rebuild/rebuild.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/rebuild/rebuild.sh b/apps/rebuild/rebuild.sh index 177a35b..d04ed21 100755 --- a/apps/rebuild/rebuild.sh +++ b/apps/rebuild/rebuild.sh @@ -1,15 +1,15 @@ # NixOS and standalone Home Manager rebuild script # Defaults -FLAKE_PATH="$HOME/.config/nixos" # Default flake path -HOME_USER="$(whoami)" # Default username. Used to identify the Home Manager configuration -NIXOS_HOST="$(hostname)" # Default hostname. Used to identify the NixOS and Home Manager configuration -BUILD_HOST="" # Default build host. Empty means localhost -TARGET_HOST="" # Default target host. Empty means localhost -UPDATE=0 # Default to not update flake repositories -UPDATE_INPUTS="" # Default list of inputs to update. Empty means all -ROLLBACK=0 # Default to not rollback -SHOW_TRACE=0 # Default to not show detailed error messages +FLAKE_PATH="${REBUILD_FLAKE_PATH:-${FLAKE_PATH:-$HOME/.config/nixos}}" # Default flake path +USER="${REBUILD_USER:-$(whoami)}" # Default username +HOST="${REBUILD_HOST:-$(hostname)}" # Default hostname +BUILD_HOST="${REBUILD_BUILD_HOST:-}" # Default build host +TARGET_HOST="${REBUILD_TARGET_HOST:-}" # Default target host +UPDATE="${REBUILD_UPDATE:-0}" # Default to not update +UPDATE_INPUTS="${REBUILD_UPDATE_INPUTS:-}" # Default list of inputs +ROLLBACK="${REBUILD_ROLLBACK:-0}" # Default to not rollback +SHOW_TRACE="${REBUILD_SHOW_TRACE:-0}" # Default to not show trace # Output functions _status() { echo -e "\033[0;34m> $1\033[0m"; } @@ -28,7 +28,7 @@ Help() { echo " help Show this help message" echo echo "Options (for NixOS and Home Manager):" - echo " -H, --host Specify the hostname (as in 'nixosConfiguraions.'). Default: $NIXOS_HOST" + echo " -H, --host Specify the hostname (as in 'nixosConfiguraions.'). Default: $HOST" echo " -p, --path Set the path to the flake directory. Default: $FLAKE_PATH" echo " -U, --update [inputs] Update all flake inputs. Optionally provide comma-separated list of inputs to update instead." echo " -r, --rollback Don't build the new configuration, but use the previous generation instead" @@ -39,12 +39,12 @@ Help() { echo " -T, --target-host Deploy the configuration to a remote host via SSH. If '--host' is specified, it will be used as the target host." echo echo "Home Manager only options:" - echo " -u, --user Specify the username (as in 'homeConfigurations.@'). Default: $HOME_USER" + echo " -u, --user Specify the username (as in 'homeConfigurations.@'). Default: $USER" } # Function to rebuild NixOS configuration Rebuild_nixos() { - local FLAKE="$FLAKE_PATH#$NIXOS_HOST" + local FLAKE="$FLAKE_PATH#$HOST" # Construct rebuild command local CMD=("nixos-rebuild" "switch" "--sudo") @@ -52,8 +52,8 @@ Rebuild_nixos() { [ "$ROLLBACK" = 1 ] && CMD+=("--rollback") [ "$SHOW_TRACE" = 1 ] && CMD+=("--show-trace") [ -n "$BUILD_HOST" ] && CMD+=("--build-host" "$BUILD_HOST") - if [ "$NIXOS_HOST" != "$(hostname)" ] && [ -z "$TARGET_HOST" ]; then - TARGET_HOST="$NIXOS_HOST" + if [ "$HOST" != "$(hostname)" ] && [ -z "$TARGET_HOST" ]; then + TARGET_HOST="$HOST" _status "Using '$TARGET_HOST' as target host." fi [ -n "$TARGET_HOST" ] && CMD+=("--target-host" "$TARGET_HOST") @@ -82,7 +82,7 @@ Rebuild_nixos() { # Function to rebuild Home Manager configuration Rebuild_home() { - local FLAKE="$FLAKE_PATH#$HOME_USER@$NIXOS_HOST" + local FLAKE="$FLAKE_PATH#$USER@$HOST" if [ -n "$BUILD_HOST" ] || [ -n "$TARGET_HOST" ]; then error "Remote building is not supported for Home Manager." @@ -156,7 +156,7 @@ while [ $# -gt 0 ]; do case "${1:-}" in -H|--host) if [ -n "${2:-}" ]; then - NIXOS_HOST="$2" + HOST="$2" shift 2 else error "-H|--host option requires an argument" @@ -164,7 +164,7 @@ while [ $# -gt 0 ]; do ;; -u|--user) if [ -n "${2:-}" ]; then - HOME_USER="$2" + USER="$2" shift 2 else error "-u|--user option requires an argument"