-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild
executable file
·36 lines (30 loc) · 938 Bytes
/
rebuild
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env zsh
# for compdef if I ever work it out.
# hosts=($(tailscale status | grep -v 'offline' | awk '{print $2}'))
# configurations=($(nix flake show --json 2> /dev/null | jq '.nixosConfigurations' | jq -r 'keys' | tr -d '[], "'))
#
# configured_hosts=(${hosts:*configurations})
# configured_hosts=(${configured_hosts#$(hostname)})
zmodload zsh/zutil
zparseopts -D -E - \
t:=target -target:=target \
b:=builder -builder:=builder \
c:=config -configuration:=config \
|| exit 1
if [[ ! -z $target ]]; then
target[1]='--target-host'
fi
if [[ ! -z $builder ]]; then
builder[1]='--build-host'
elif [[ ! -z $target ]]; then
builder=( '--build-host' "${target[2]}" )
fi
if [[ ! -z $config ]]; then
config=('--flake' ".#${config[2]}")
elif [[ ! -z $target ]]; then
config=('--flake' ".#${target[2]}")
else
config=('--flake' ".")
fi
export NIX_SSHOPTS="-A"
nixos-rebuild $config $target $builder --use-remote-sudo $@