From e7e650a26f6f50ce75c8baa4868eeca7c3190e12 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sat, 20 Sep 2025 11:16:49 +0200 Subject: refactor: decouple rebuild script from current dir --- nixos/rebuild | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'nixos/rebuild') diff --git a/nixos/rebuild b/nixos/rebuild index 7fa750a..d902bd8 100755 --- a/nixos/rebuild +++ b/nixos/rebuild @@ -1,10 +1,8 @@ #!/usr/bin/env bash set -euo pipefail -# Enable all future paths in this script to be relative to the directory containing the script. -cd "$(dirname -- "${BASH_SOURCE[0]}")" - -configPath=$(realpath -- "hosts/$HOSTNAME/default.nix") +top=$(dirname "$(realpath "$0")") +configPath="$top/hosts/$HOSTNAME/default.nix" if [ ! -f $configPath ]; then echo "aborting: $configPath doesn't exist" @@ -12,6 +10,7 @@ if [ ! -f $configPath ]; then fi nixpkgsPath=$( + cd "$top" && nix-instantiate --eval --raw \ --argstr host "$HOSTNAME" \ --expr ' @@ -24,6 +23,8 @@ nixpkgsPath=$( ' ) +# FIXME: change into host directory for host-specific garbage collector roots +cd "$top" # nixos-rebuild always reads Nixpkgs from the NIX_PATH, # so we need to set it explicitly to our pinned version -exec nixos-rebuild "$@" -I nixpkgs="$nixpkgsPath" -I nixos-config="$configPath" -I top="$(pwd)" +exec nixos-rebuild "$@" -I nixpkgs="$nixpkgsPath" -I nixos-config="$configPath" -I top="$top" -- cgit v1.2.3