#!/usr/bin/env bash set -euo pipefail top=$(dirname "$(realpath "$0")") hostDir="$top/hosts/$HOSTNAME" if [ ! -d "$hostDir" ]; then echo "aborting: host directory $hostDir doesn't exist" exit 1 fi # Make the configuration repository's commit available to the NixOS module. export NIXOS_CONFIG_REVISION NIXOS_CONFIG_REVISION=$(git -C "$top" rev-parse --verify HEAD) if [[ -n $(git -C "$top" status --porcelain) ]]; then NIXOS_CONFIG_REVISION+="-dirty" fi ( # 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 "$hostDir" && exec nixos-rebuild "$@" --file "$top/default.nix" --attr "configurations.$HOSTNAME" )