-
Notifications
You must be signed in to change notification settings - Fork 0
/
nuh
executable file
·99 lines (87 loc) · 1.8 KB
/
nuh
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
#!/usr/bin/env bash
version=0.1.0
# Changelog:
# v0.1.0 - initial version
# Current exit modes:
# 0 - success
# 1 - no verb specified
me=$(basename $0)
sudo=${NUH_SUDO:-sudo}
dir=${NUH_DIR:-~/infra}
verb=$1
shift
function help() {
cat 1>&2 <<EOF
nuh v$version - the NixOS Update Helper
Usage: $me <verb> [arguments]
Current infrastructure directory: $dir
Verbs:
search [query] - find a package by keyword(s)
update - update the system flake
upgrade - update the system flake and rebuild the system
clean - clean up unused and cached files
shrink - save space by hard-linking files
try [package] - try out a new package in an ephemral shell
show - show a tree view of your current infra directory
edit [module] - edit a file in your infra directory
help - print this help
version - print the version number
EOF
}
# Meta
case "$verb" in
'')
help
echo "$me: a verb is required" 1>&2
exit 1
;;
help|h|\?|-\?|-h|-help|--help)
help
exit 0
;;
version|v|-v|-version|--version)
echo "nuh v$version"
exit 0
;;
esac
# Acions
case "$verb" in
search|query)
exec nix search "nixpkgs#legacyPackages.x86_64-linux" "$@"
;;
update)
cd $dir
exec $sudo nix flake update --no-warn-dirty "$@"
;;
upgrade|up|u)
cd $dir
rm -f ~/.cache/tofi-drun # Grrrrr Tofi needs this to be cleared
$sudo nix flake update --no-warn-dirty
exec $sudo nixos-rebuild switch "$@"
;;
clean)
exec $sudo nix store gc "$@"
;;
shrink|optimise|optimize)
exec $sudo nix store optimise "$@"
;;
try|t)
exec nix shell "nixpkgs#$@"
;;
show|s)
exec eza --tree $dir "$@"
;;
edit|e)
exec $EDITOR "$dir/$@"
;;
# Easter eggs
uh)
echo "yuh-uh !"
exit 0
;;
# Catch-all
*)
echo "$me: unknown verb: $verb" 1>&2
exit 1
;;
esac