-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply
executable file
·66 lines (51 loc) · 1.55 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
#! /usr/bin/env bash
set -e
PATH="$PATH:./bin"
OFFLINE=""
if [[ "$1" == "--offline" ]]; then
OFFLINE="--offline"
fi
set -u
if command -v scutil &>/dev/null; then
ag 'TODO:' || true # ignore this
fi
HN=$(hostname_wrapper)
# minimally, yell if nix version out of date
upgrade_nix
OSC="nixosConfigurations"
OS=$(uname -a)
if [[ "$OS" == *"Darwin"* ]]; then
OSC="darwinConfigurations"
fi
# TODO: is there a cleaner way of doing this?
# this doesn't work with darwinConfigurations yet.
# nix flake show --extra-experimental-features "flakes nix-command" --impure .
VALID_HOSTNAMES=$(grep "$OSC" flake.nix | grep -o '".*"' | sed 's/"//g')
if [[ ! "${VALID_HOSTNAMES[*]}" =~ $HN ]]; then
echo "invalid hostname: '$HN'"
echo "sudo scutil --set LocalHostName ..."
exit 1
fi
if [[ "$OS" == *"Darwin"* ]]; then
nix build ".#${OSC}.${HN}.system" --impure --extra-experimental-features "nix-command flakes" --show-trace # "$OFFLINE"
else
nix build ".#${OSC}.${HN}.config.system.build.toplevel" --impure --extra-experimental-features "nix-command flakes" --show-trace # "$OFFLINE"
fi
# if possible, diff the derivations and ask for input
if command -v nvd; then
nvd diff /run/current-system result
if command -v nix-diff; then
nix-diff --line-oriented --context 5 /run/current-system result
fi
if opt_out "Continue?"; then
exit 0
fi
fi
if [[ "$OS" == *"Darwin"* ]]; then
echo "darwin-rebuild"
./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