1#!/bin/sh
2set -e
3cd "$(dirname "$0")"
4nh_subcommand="os"
5fallback_command="nixos-rebuild"
6if [ -n "$1" ]; then
7 hostname="$1"
8elif [ -f ".hostname" ]; then
9 hostname=$(cat .hostname)
10fi
11if [ -z "$hostname" ]; then
12 hostname="$(hostname)"
13fi
14printf "%s" "$hostname" >.hostname
15if [ "$(uname -s)" = "Darwin" ]; then
16 nh_subcommand="darwin"
17 fallback_command="nix run .#darwin-rebuild"
18fi
19if command -v nh >/dev/null; then
20 if [ "$nh_subcommand" = "darwin" ]; then
21 nh darwin switch . --hostname "$hostname"
22 else
23 nh os switch '.#'"$hostname"
24 fi
25else
26 $fallback_command -- switch --flake '.#'"$hostname"
27fi