-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.justfile
177 lines (154 loc) · 4.58 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
set quiet := true
set fallback := true
set shell := ["bash", "-c"]
PATH := "~/nixed0"
FLAKE := "nixed0"
PROFILE := "uxodb"
#sudo nixos-rebuild switch --flake {{PATH}}#{{FLAKE}}
#home-manager switch --impure --flake {{PATH}}#{{PROFILE}}
[doc('Show this list')]
help *args="":
#!/usr/bin/env bash
if [ -z "{{args}}" ]; then
just --list
else
if just --summary | grep -q "^{{args}}\b"; then
just info "Info for recipe: {{args}}"
just --show {{args}}
else
just error "Recipe '{{args}}' not found"
just --list
fi
fi
#######
##OPS##
#######
[doc("Switch NixOS or HM config or both. nixos,home,all")]
switch option="home":
#!/usr/bin/env bash
case "{{option}}" in
"nixos")
just warn "Switching NixOS configuration..."
nh os switch ~/nixed0
;;
"home")
just warn "Switching home-manager configuration..."
nh home switch ~/nixed0 -- --impure
;;
"all")
just warn "Switching both NixOS and HM configurations..."
nh os switch ~/nixed0
nh home switch ~/nixed0 -- --impure
;;
*)
just error "Invalid option: {{option}}"
just info "Available options: nixos, home, all"
exit 1
;;
esac
[doc("Collect garbage and also collect and rebuild boot with: all")]
clean *args="":
#!/usr/bin/env bash
if [[ "{{args}}" == "all" ]]; then
just warn "Garbage collector: collect all and rebuild boot"
sleep 1
sudo nix-collect-garbage
sudo nix-collect-garbage --delete-old
else
just warn "Garbage collector: unreferenced packages"
sleep 1
sudo nix-collect-garbage
fi
[doc("Update inputs or single input. <input>")]
update +inputs="all":
#!/usr/bin/env bash
if [[ "{{inputs}}" == "all" ]]; then
just warn "Updating all flake inputs.."
sleep 1
sudo nix flake update;
else
just info "Updating flake inputs: {{inputs}}"
sleep 1
sudo nix flake update {{inputs}};
fi
[doc("Search for nixos and hm options. <option>")]
search option:
just info "Looking for option <{{option}}> in hm- and nixos-options"
manix {{option}} --source hm_options,nixos_ptions
[doc("Show latest home-manager news")]
news:
home-manager news --flake {{PATH}}#{{PROFILE}}
[doc("Optimise store (hardlinks)")]
optimise:
just info "Optimise store..."
sudo nix-store --optimise
[doc("Set current generation as default boot gen")]
setboot:
just warn "Setting default boot generation to current..."
sleep 2
sudo /run/current-system/bin/switch-to-configuration boot
########
##PREP##
########
[doc("Prepares and builds the config on a fresh system")]
build: && _main _generate-hardware _gitremote _bwlogout
just warn "Starting build sequence in 3 seconds..."
sleep 3
_sops:
#!/usr/bin/env bash
just warn "Creating ssh folder in $HOME"
mkdir $HOME/.ssh
ls -ld $HOME/.ssh
keyFile=$HOME/.config/sops/age/keys.txt
just warn "Preparing folder in .config for key."
mkdir -p $HOME/.config/sops/age
just info "$(ls -ld $HOME/.config/sops/age)"
bw list items --search SOPS | jq -r '.[].notes' > $keyFile
just warn "Exported age key from Bitwarden to ~/.config/sops/age/keys.txt"
just info "$(ls -ld $HOME/.config/sops/age/keys.txt)"
just info "$(cat $HOME/.config/sops/age/keys.txt)"
_main:
just warn "Login to bitwarden when prompted, keep 2FA ready."
export BW_SESSION=$(bw login | grep 'export BW_SESSION' | awk -F '"' '{print $2}') && just warn "Exported var: $BW_SESSION" && just _sops
_bwlogout:
just warn "Logging out of Bitwarden-cli..."
bw logout
just info "Build complete."
just info "To start building the flake, run the _firstbuild recipe"
_generate-hardware:
just warn "Generating hardware config and overwriting old..."
nixos-generate-config --show-hardware-config > $HOME/nixed0/host/hardware.nix
just info "$(ls -ld $HOME/nixed0/host/hardware.nix)"
_gitremote:
#!/usr/bin/env bash
if [[ "$PWD" != "~/nixed0" ]]; then
just warn "PWD is not repo, moving into repo"
cd $HOME/nixed0/
fi
just info "Current remote:"
git remote -v
just warn "Setting new remote..."
git remote set-url origin [email protected]:uxodb/nixed0.git
just info "Remote set"
git remote -v
_firstbuild:
sudo nixos-rebuild switch --flake {{PATH}}#{{FLAKE}} --use-remote-sudo
home-manager switch --impure --flake {{PATH}}#{{PROFILE}}
########
##PRIV##
########
BLUE := '\033[1;30;44m'
RED := '\033[1;30;41m'
YELLOW := '\033[1;30;43m'
NC := '\033[0m'
[private]
info msg:
@echo -e "{{BLUE}} => {{NC}} {{msg}}"
[private]
warn msg:
@echo -e "{{YELLOW}} !? {{NC}} {{msg}}"
[private]
error msg:
@echo -e "{{RED}} != {{NC}} {{msg}}"
[private]
alias s := switch