From 748d3282d351107723e79060a9471b08e66c4670 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Wed, 30 Sep 2026 10:59:24 +0200 Subject: refactor: move absolute path imports to private.nix --- nixos/rebuild | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'nixos/rebuild') diff --git a/nixos/rebuild b/nixos/rebuild index 9e62b33..d6a06a8 100755 --- a/nixos/rebuild +++ b/nixos/rebuild @@ -2,9 +2,25 @@ set -euo pipefail top=$(dirname "$(realpath "$0")") -configPath="$top/hosts/$HOSTNAME/default.nix" +hostDir="$top/hosts/$HOSTNAME" +defaultConfigPath="$hostDir/default.nix" +privateConfigPath="$hostDir/private.nix" -if [ ! -f $configPath ]; then +case "${1:-}" in + --default) + configPath="$defaultConfigPath" + shift + ;; + *) + if [ -f "$privateConfigPath" ]; then + configPath="$privateConfigPath" + else + configPath="$defaultConfigPath" + fi + ;; +esac + +if [ ! -f "$configPath" ]; then echo "aborting: $configPath doesn't exist" exit 1 fi @@ -27,7 +43,7 @@ nixpkgsPath=$( # The result symlink created in the current directory is registered as a root of the Nix # garbage collector, so it's important that we call nixos-rebuild from the host directory. # (nix-build has an --out-link option but that option cannot be set via nixos-rebuild). - cd $top/hosts/$HOSTNAME && + cd "$hostDir" && # nixos-rebuild always reads Nixpkgs from the NIX_PATH, # so we need to set it explicitly to our pinned version -- cgit v1.3.1