-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
87 lines (68 loc) 路 2.2 KB
/
justfile
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
default: switch
# Rebuild the system and apply the changes
switch:
#!/usr/bin/env bash
set -euo pipefail
if [ ! -f "host.nix" ]
then
echo "host.nix was not found, please generate one using \`just generate-host\` and then try again"
exit 1
fi
echo "Staging host.nix with git add -N and assuming it won't get updated"
git add -N host.nix && git update-index --assume-unchanged host.nix
DID_FAIL=0
OS_NAME="$(uname)"
case "$OS_NAME" in
Darwin) just darwin-rebuild-switch ;;
*) echo "Not sure how to support $OS_NAME" && DID_FAIL=1 ;;
esac
# Rebuild using darwin-rebuild and apply the changes
darwin-rebuild-switch:
#!/usr/bin/env bash
set -euo pipefail
if command -v darwin-rebuild > /dev/null
then
darwin-rebuild switch --flake "$PWD"#macbook
exit 0
fi
echo "darwin-rebuild not found, using nix run instead"
nix run nix-darwin -- switch --flake "$PWD"#macbook
# Rebuild using darwin-rebuild but don't apply the changes
darwin-rebuild-build:
#!/usr/bin/env bash
set -euo pipefail
if command -v darwin-rebuild > /dev/null
then
darwin-rebuild build --flake "$PWD"#macbook
exit 0
fi
echo "darwin-rebuild not found, using nix run instead"
nix run nix-darwin -- build --flake "$PWD"#macbook
# Rollback using darwin-rebuild
darwin-rebuild-rollback:
#!/usr/bin/env bash
set -euo pipefail
if command -v darwin-rebuild > /dev/null
then
darwin-rebuild build --flake "$PWD"#macbook --rollback
exit 0
fi
echo "darwin-rebuild not found, using nix run instead"
nix run nix-darwin -- build --flake "$PWD"#macbook --rollback
# Run a repl
repl:
nix repl
# Generate the host file
generate-host:
#!/usr/bin/env bash
MESSAGE="This file is automatically generated using \`just generate-host\`"
printf '# %s\n{ username = "%s"; hostname = "%s"; }\n' "$MESSAGE" "$(whoami)" "$(hostname)" | tee host.nix
# Update the flake
update:
#!/usr/bin/env bash
nix flake update
if [ ! -z "$(git diff --name-only ./flake.lock)" ]
then
git add ./flake.lock
git commit -m "Update Flake inputs" -- ./flake.lock
fi