-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.sh
More file actions
executable file
·62 lines (51 loc) · 1.18 KB
/
switch.sh
File metadata and controls
executable file
·62 lines (51 loc) · 1.18 KB
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
#!/usr/bin/env bash
set -e
usage_str="Usage: $0 [darwin|nixos|home] [-h]"
if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
echo "$usage_str"
exit 1
fi
TARGET="$1"
SWITCH_HOME=false
if [ "$2" == "-h" ]; then
SWITCH_HOME=true
fi
# load in config
CONFIG_FILE="$HOME/nix/config.sh"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config file not found: $CONFIG_FILE"
exit 1
fi
source "$CONFIG_FILE"
# variables needed in config.sh:
# FLAKE_DIR, path to flake dir ("$HOME/nix") (no longer needed for nh)
# CONFIG_NAME, name of the configuration ("macbook-pro")
# FLAKE="$FLAKE_DIR#$CONFIG_NAME"
switch_home() {
echo "Running home-manager..."
# home-manager switch --flake "$FLAKE"
nh home switch -c "$CONFIG_NAME"
}
case "$TARGET" in
nixos|n)
echo "Running nixos-rebuild..."
# sudo nixos-rebuild switch --flake "$FLAKE"
nh os switch -H "$CONFIG_NAME"
;;
darwin|d)
echo "Running darwin-rebuild..."
# sudo darwin-rebuild switch --flake "$FLAKE"
nh darwin switch -H "$CONFIG_NAME"
;;
home|h)
switch_home
;;
*)
echo "Unknown target: $TARGET"
echo "$usage_str"
exit 1
;;
esac
if $SWITCH_HOME && [[ "$TARGET" != "home" ]]; then
switch_home
fi