-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrebuild-os.sh
executable file
·65 lines (52 loc) · 1.31 KB
/
rebuild-os.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# Copyright (c) 2025 tsrk. <[email protected]>
# This file is licensed under the MIT License.
# See the LICENSE file in the repository root for more info.
#
# SPDX-License-Identifier: MIT
# This script is a wrapper around `nixos-rebuild` and `nom` (nix-output-monitor)
# to make rebuilding a nixos system in this flake more informative while having
# less boilerplate arguments to write manually
set -euo pipefail
print_usage() {
echo 'Usage: ./rebuild-os <action> <host> [OPTIONS...]' >&2
exit 2
}
sudo_() {
if [ "$UID" -eq 0 ]; then
"$@"
else
sudo "$@"
fi
}
darkman_() {
if command -v darkman &>/dev/null; then
darkman "$@"
else
nix run nixpkgs#darkman -- "$@"
fi
}
nom_() {
if command -v nom &>/dev/null; then
nom "$@"
else
nix run nixpkgs#nix-output-monitor -- "$@"
fi
}
if [ "$#" -lt 2 ]; then
print_usage
fi
rebuild_command="$1"
shift 1
nix_host="$1"
shift 1
# Ensure user is logged in as root as sudo prompt will not be available
# afterwards, because we are also piping stderr to nom
sudo_ true
(sudo_ nixos-rebuild $rebuild_command --fast -L -v --log-format internal-json \
--flake .#"$nix_host" "$@") |& nom_ --json
if [ "$(darkman_ get)" = "light" ]; then
exec hm-light-activate
else
exec hm-dark-activate
fi