-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply
executable file
·114 lines (94 loc) · 2.27 KB
/
apply
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#! /usr/bin/env bash
set -e
PATH="$PATH:./bin"
OS=$(uname -a)
IS_MAC=
IS_NIX=
if [[ "$OS" == *"NixOS"* ]]; then
IS_NIX=true
fi
if [[ "$OS" == *"Darwin"* ]]; then
IS_MAC=true
fi
OFFLINE=""
if [[ "$1" == "--offline" ]]; then
OFFLINE="--offline"
fi
set -u
if command -v scutil &>/dev/null; then
rg --pcre2 'TODO:(?!.*# ignore)' || true # ignore
fi
HN=$(hostname_wrapper)
# minimally, yell if nix version out of date
upgrade_nix
set +e
if ! ssh-add -l >/dev/null; then
ssh-add ~/.ssh/id_ed25519
fi
set -e
OSC="nixosConfigurations"
if [[ "$IS_MAC" ]]; then
OSC="darwinConfigurations"
set +e
if ! xcode_license_accepted; then
sudo xcodebuild -license
fi
set -e
fi
VALID_HOSTNAMES=$(get-flake-configurations)
if [[ ! "${VALID_HOSTNAMES[*]}" =~ $HN ]]; then
echo "invalid hostname: '$HN'"
if confirm "override hostname?"; then
while true; do
read -r FAUX_HOST
if [[ "${VALID_HOSTNAMES[*]}" =~ $FAUX_HOST ]]; then
if confirm "use $FAUX_HOST?"; then
HN="$FAUX_HOST"
break
fi
fi
done
else
if [[ "$IS_MAC" ]]; then
echo "sudo scutil --set LocalHostName ..."
elif [[ "$IS_NIX" ]]; then
echo "put in /etc/nixos/configuration.nix: "
echo "networking.hostName = \"$HN\";"
echo "sudo nixos-rebuild switch"
echo "sudo reboot"
fi
exit 1
fi
fi
if [[ "$IS_MAC" ]]; then
nix build ".#${OSC}.${HN}.system" --impure --extra-experimental-features "nix-command flakes" $OFFLINE --show-trace
else
nix build ".#${OSC}.${HN}.config.system.build.toplevel" --impure --extra-experimental-features "nix-command flakes" $OFFLINE --show-trace
fi
# if possible, diff the derivations and ask for input
if command -v nvd; then
nvd diff /run/current-system result
if opt_out "nvd ^ Continue?"; then
exit 0
fi
if command -v nix-diff; then
nix-diff --line-oriented --context 5 /run/current-system result
fi
if opt_out "nix-diff ^ Continue?"; then
exit 0
fi
fi
if [[ "$IS_MAC" ]]; then
echo "darwin-rebuild"
if [[ -f /etc/bashrc ]]; then
sudo mv -f /etc/bashrc /etc/bashrc.backup-before-nix
fi
if [[ -f /etc/zshrc ]]; then
sudo mv -f /etc/zshrc /etc/bashrc.backup-before-nix
fi
./result/sw/bin/darwin-rebuild switch --flake . --impure
else
sudo nixos-rebuild switch --flake . --impure
fi
date >last-applied.txt
# source ~/.config/fish/config.fish