-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathjustfile
More file actions
282 lines (260 loc) · 10.5 KB
/
Copy pathjustfile
File metadata and controls
282 lines (260 loc) · 10.5 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
set dotenv-load
help:
@just --list
# Install apps into nix profile, 'just install-nix "foo bar"
install-nix nix_apps args="":
@for app in {{nix_apps}}; do \
if !(nix profile list | rg -q -F "\.${app}"); then \
echo "Installing ${app}"; \
outputs=$(nix eval nixpkgs#${app}.outputs |sed 's/[]["]//g'); \
for out in $outputs; do \
echo "Building output ${out} for ${app}"; \
nix build {{ args }} nixpkgs#${app}.${out}; \
done; \
nix profile install {{ args }} nixpkgs#${app}; \
else \
echo "Package ${app} already installed, skipping"; \
fi \
done
# Install an app from its own flake (not in nixpkgs), e.g. 'just install-flake
# "github:owner/repo"'. --accept-flake-config trusts the flake's declared cache.
install-flake flake_ref:
@if nix profile list | rg -q -F "{{flake_ref}}"; then \
echo "Flake {{flake_ref}} already installed, skipping"; \
else \
echo "Installing {{flake_ref}}"; \
nix profile install --accept-flake-config "{{flake_ref}}"; \
fi
# Install apps that ship their own flake rather than living in nixpkgs
install-flake-apps:
@just install-flake "github:modem-dev/hunk"
@just install-flake "github:agent-of-empires/agent-of-empires"
# Install fun apps
install-fun-apps: (install-nix "boxes cowsay figlet fortune lolcat toilet fastfetch")
# Install apps for every day use
install-system-apps:
@just install-nix "act"
@just install-nix "aider-chat"
@just install-nix "asciinema"
@just install-nix "asciinema-agg"
@just install-nix "ast-grep"
@just install-nix "atuin"
@just install-nix "azure-cli"
@just install-nix "bash"
@just install-nix "bat"
@just install-nix "bottom"
@just install-nix "cheat"
@just install-nix "cmake"
@just install-nix "cairo"
@just install-nix "colima"
@just install-nix "colordiff"
@just install-nix "coreutils"
@just install-nix "crane"
@just install-nix "cue"
@just install-nix "delta"
@just install-nix "direnv"
@just install-nix "docker-client"
@just install-nix "docker-compose"
@just install-nix "docker-credential-helpers"
@just install-nix "docker-ls"
@just install-nix "duf"
@just install-nix "dwdiff"
@just install-nix "earthly"
@just install-nix "easyrsa"
@just install-nix "eza"
@just install-nix "ffmpeg"
@just install-nix "flock"
@just install-nix "fontconfig"
@just install-nix "freetype"
@just install-nix "fzf"
@just install-nix "google-cloud-sdk"
@just install-nix "gettext"
@just install-nix "gh"
@just install-nix "git"
@just install-nix "git-crypt"
@just install-nix "gnumake"
@just install-nix "gnupg"
@just install-nix "graphviz"
@just install-nix "harfbuzz"
@just install-nix "heroku"
@just install-nix "htop"
@just install-nix "icu"
@just install-nix "imagemagick"
@just install-nix "jless"
@just install-nix "jq"
@just install-nix "k6"
@just install-nix "k9s"
@just install-nix "libgit2"
@just install-nix "libffi"
@just install-nix "libpng"
@just install-nix "tokei"
@just install-nix "lz4"
@just install-nix "minikube"
@just install-nix "mise"
@just install-nix "ncurses"
@just install-nix "ngrok" "--impure"
@just install-nix "openssl"
@just install-nix "openvpn"
@just install-nix "pandoc"
@just install-nix "pango"
@just install-nix "pdfgrep"
@just install-nix "pixman"
@just install-nix "pkg-config"
@just install-nix "poppler-utils"
@just install-nix "postgresql.dev"
@just install-nix "pre-commit"
@just install-nix "protobuf"
@just install-nix "pwgen"
@just install-nix "neovim"
@just install-nix "readline"
@just install-nix "ripgrep"
@just install-nix "sd"
@just install-nix "shellcheck"
@just install-nix "starship"
@just install-nix "stow"
@just install-nix "terraform-docs"
@just install-nix "tree"
@just install-nix "tmux"
@just install-nix "unzip"
@just install-nix "util-linux"
@just install-nix "visidata"
@just install-nix "watch"
@just install-nix "watchman"
@just install-nix "wget"
@just install-nix "xh"
@just install-nix "xz"
@just install-nix "yq-go"
@just install-nix "zellij"
@just install-nix "zsh"
# Install apps for doing SRE work
install-sre-apps:
@just install-nix "argocd awscli2 aws-nuke aws-vault dos2unix krew kubie"
@just install-nix "kind kubecolor redis sops stern teleport terraformer"
@just install-nix "qemu helm-docs kafkactl cilium-cli"
@just install-nix "ssm-session-manager-plugin"
@just install-nix "mage golangci-lint e1s granted"
# Install all applications
install: install-system-apps install-sre-apps install-fun-apps install-flake-apps
@echo "Done installing all packages"
# Upgrade all installed applications
nix-upgrade:
nix profile upgrade '.*' --impure
# Repair the nix store
nix-repair:
nix-store --repair --verify --check-contents
# Remove packages that aren't referenced
nix-gc:
nix profile wipe-history
nix-collect-garbage --delete-old
nix store gc
nix store optimise
# Installs all the dotfiles
install-dotfiles:
cd dotfiles && stow --verbose=1 --target=$HOME */
# Removes all the dotfiles
remove-dotfiles:
cd dotfiles && stow --verbose=1 --delete --target=$HOME */
# --- Dev VMs (Colima) ----------------------------------------------------
# One Linux VM per project, NAMED AFTER its ~/code subdir, so each VM mounts
# ONLY that project and can't see your other projects or $HOME:
# `just vm-up drape` -> profile "drape", mounts ~/code/drape
# `just vm-up stacklet` -> profile "stacklet", mounts ~/code/stacklet
# vz/virtiofs + the no-$HOME default also come from the stowed template
# (~/.config/colima/_templates/default.yaml); the --mount here narrows it to the
# one project (a flag mount replaces the template's broader default).
#
# RAM note: an 18GiB host can't comfortably run two 8GiB VMs at once, so the
# defaults are modest (6 CPU / 6 GiB) to let two coexist. Bump per-invocation
# for a single heavy VM: `just vm-up drape 8 12 150`. Sizing changes apply after
# a down + up. Both disks are thin-provisioned (sparse), so the numbers are
# ceilings, not upfront cost; root_disk sizes /nix (the toolchain), disk sizes
# the container-runtime store.
#
# Usage: vm-up <name> [cpu] [mem] [disk] [root_disk] | vm-down/vm-ssh/vm-status <name> | vm-list
#
# Create or start a project VM (Colima profile), then provision it. Mounts the
# named project (~/code/<name>) PLUS ~/code/sontek (homies, sontek-skills, ...)
# so your own tooling is available in every VM, PLUS ~/screenshots (read-only) so
# dragged screenshots resolve at the same path inside the VM. Bootstrap runs AFTER start (over
# ssh) because Colima's boot-time provision scripts run before DNS is up.
vm-up name cpu="6" memory="6" disk="100" root_disk="100":
#!/usr/bin/env bash
set -euo pipefail
mounts=(--mount "$HOME/code/{{name}}:w")
# Always include ~/code/sontek, unless this IS the sontek VM (no duplicate mount).
[ "{{name}}" = "sontek" ] || mounts+=(--mount "$HOME/code/sontek:w")
# Share ~/screenshots (read-only) at the SAME path so dragging a screenshot into
# an in-VM agent (aoe/claude) hands it a path that resolves identically in the VM.
# macOS saves screencaptures here: `defaults write com.apple.screencapture location`.
mounts+=(--mount "$HOME/screenshots:r")
# Two sparse disks: --root-disk holds the OS + /nix (the toolchain), --disk is
# Colima's dedicated container-runtime disk (docker/containerd). The default
# root disk is only 20 GiB, which /nix overflows, so size it explicitly.
colima start {{name}} --runtime docker --vm-type vz --mount-type virtiofs --ssh-agent \
--cpu {{cpu}} --memory {{memory}} --disk {{disk}} --root-disk {{root_disk}} "${mounts[@]}"
just vm-bootstrap {{name}}
# Provision a running VM (idempotent): ~/code bind mounts, apt prereqs
# (just/rg/curl/build-essential), Nix. Streams output here. Re-runnable any time;
# also used by `vm-up`.
vm-bootstrap name:
colima ssh -p {{name}} -- bash -s < {{justfile_directory()}}/vm-bootstrap.sh
# Stop a VM (frees RAM/CPU; disk + everything installed inside persists)
vm-down name:
colima stop {{name}}
# Shell into a VM with the local terminal's identity carried over the SSH hop,
# so OSC 8 hyperlinks (e.g. Claude Code's clickable "PR #NNNN" link), truecolor,
# and other TUI features work -- including inside a remote tmux. colima publishes
# an ssh_config (Host colima-<name>), Include'd from ~/.ssh/config, so we can ssh
# the VM directly. Handles kitty and ghostty; anything else (and inside tmux,
# where TERM is rewritten and these handshakes break) falls back to plain colima
# ssh, where hyperlinks still ride the FORCE_HYPERLINK + tmux xterm*:hyperlinks
# fallback.
vm-ssh name:
#!/usr/bin/env bash
set -euo pipefail
host="colima-{{name}}"
case "${TERM:-}" in
*kitty*)
# kitty: the ssh kitten copies terminfo and sets TERM=xterm-kitty itself
# (and Claude detects kitty straight from TERM containing "kitty").
if command -v kitten >/dev/null 2>&1; then exec kitten ssh "$host"; fi
;;
xterm-ghostty)
# ghostty has no kitten. Push its terminfo to the VM if missing, then force
# TERM on the remote login shell -- lima's sshd ignores a forwarded/SetEnv
# TERM, so it only sticks when set in the remote command. Also set
# TERM_PROGRAM, which is how Claude detects ghostty (TERM alone won't).
ssh "$host" -- 'infocmp xterm-ghostty >/dev/null 2>&1' \
|| infocmp -x xterm-ghostty | ssh "$host" -- 'tic -x -' >/dev/null 2>&1 || true
exec ssh -t "$host" -- 'TERM=xterm-ghostty TERM_PROGRAM=ghostty exec "$SHELL" -l'
;;
esac
exec colima ssh -p {{name}}
# Show a VM's status and address
vm-status name:
colima status {{name}}
# List all VMs and their state
vm-list:
colima list
asdf_plugins := "nodejs python golang helm yarn poetry kubectl kustomize terraform terragrunt postgres pnpm sentinel skaffold tilt rust kops"
# Configure ASDF with all desired plugins
setup-asdf:
@for plugin in {{asdf_plugins}}; do \
asdf plugin list|grep ${plugin} > /dev/null; \
if [ $? -ne 0 ]; then \
echo 'Adding asdf' ${plugin}; \
asdf plugin add ${plugin}; \
else \
echo "Asdf plugin ${plugin} already installed. Removing it"; \
asdf plugin remove ${plugin}; \
asdf plugin add ${plugin}; \
fi \
done
# Setup development language environments
setup-dev: setup-asdf
setup-krew:
krew install krew
kubectl krew install neat
kubectl krew install oidc-login
kubectl krew install resource-capacity
kubectl krew install ctx