-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·392 lines (352 loc) · 12.4 KB
/
init.sh
File metadata and controls
executable file
·392 lines (352 loc) · 12.4 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/usr/bin/env bash
set -e
# Sanity check
#
if [[ ! -f "$HOME/.config/nix/flake.nix" ]]; then
echo "This configuration must be cloned into $HOME/.config/nix!"
exit
fi
# Set OS type
#
OS="$(uname -s)"
# On normal Debian VMs, giving our user unrestricted sudo access will
# make the remainder of the setup process MUCH less annoying (this is
# set up out-of-the-box on the Android VM)
#
if [[ "$OS" == "Linux" ]] && [[ ! -d /mnt/internal ]]; then
echo "droid ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/droid
fi
# Work around flakey DNS in the Android VM
#
if [[ "$OS" == "Linux" ]]; then
if [[ $(grep -c "^nameserver 1.1.1.1" /etc/resolv.conf) -eq 0 ]]; then
sudo tee /etc/resolv.conf <<-EOF
nameserver 1.1.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF
fi
fi
# Install (or set up) Homebrew
#
if [[ "$OS" == "Darwin" ]]; then
if [[ ! -x /opt/homebrew/bin/brew ]] && [[ ! -x /usr/local/bin/brew ]]; then
xcode-select --install || true
until xcode-select -p &>/dev/null; do
sleep 4
done
curl -fsSL https://github.com/Homebrew/install/HEAD/install.sh | env NONINTERACTIVE=1 bash
fi
if [[ -x /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv bash)"
elif [[ -x /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv bash)"
else
echo "Cannot find Homebrew installation!"
exit 1
fi
fi
# Keep installation slim on Debian
#
if [[ "$OS" == "Linux" ]]; then
sudo mkdir -p /etc/apt/apt.conf.d
sudo tee /etc/apt/apt.conf.d/99local <<-EOF
APT::Install-Recommends "0";
APT::Install-Suggests "0";
EOF
fi
# Make sure that required packages are installed
#
if [[ "$OS" == "Linux" ]]; then
if [[ -f /etc/apt/sources.list.d/debian.sources ]]; then
sudo sed -i 's#^Components: .*$#Components: main contrib non-free non-free-firmware#' /etc/apt/sources.list.d/debian.sources
else
sudo sed -i 's# main$# main contrib non-free non-free-firmware#' /etc/apt/sources.list
fi
sudo apt update -y
sudo apt full-upgrade -y
sudo apt install -y curl dconf-service dialog man-db
sudo apt autoremove -y --purge --autoremove
fi
# Install Nix
#
if [[ ! -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then
curl -fsSL https://install.determinate.systems/nix | sh -s -- install --determinate --no-confirm
fi
if [[ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then
source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
fi
if [[ $(grep -c "^trusted-users = " /etc/nix/nix.custom.conf) -eq 0 ]]; then
if [[ "$OS" == "Darwin" ]]; then
echo "trusted-users = root @admin" | sudo tee -a /etc/nix/nix.custom.conf
sudo launchctl kickstart -k system/systems.determinate.nix-daemon
else
echo "trusted-users = root @sudo" | sudo tee -a /etc/nix/nix.custom.conf
sudo systemctl restart nix-daemon.service
fi
fi
# Install desktop on Debian VM
#
# NOTE: The `bubblewrap` package is required by Claude Code, but is
# pulled in automatically as a dependency of `gnome-session`
#
# NOTE: We need to install all system packages *before* building our
# dotfiles, as otherwise calls to gsettings will fail!
#
if [[ "$OS" == "Linux" ]]; then
pkill weston || true
sudo apt install -y \
adwaita-icon-theme-legacy \
build-essential \
dconf-editor \
gdm3 \
gnome-session \
libseccomp-dev \
procps \
ptyxis \
seahorse
# Additional packages to install on normal Debian VMs
#
if [[ ! -d /mnt/internal ]]; then
sudo apt install -y spice-vdagent
fi
# Comment out global SSH option that Nix's ssh binary doesn't like
#
sudo sed -i 's/^ GSSAPIAuthentication yes/# GSSAPIAuthentication yes/' /etc/ssh/ssh_config
# GNOME auto-login
#
sudo sed -i 's/^#.*AutomaticLoginEnable.*=.*/AutomaticLoginEnable = true/' /etc/gdm3/daemon.conf
sudo sed -i "s/^#.*AutomaticLogin.*=.*/AutomaticLogin = $USER/" /etc/gdm3/daemon.conf
# I mostly exist in US Mountain Time
#
sudo ln -sf /usr/share/zoneinfo/America/Denver /etc/localtime
# Tweak Android terminal theme
#
if [[ -f /etc/systemd/system/ttyd.service ]]; then
sudo sed -i "s/-t disableLeaveAlert=true/-t disableLeaveAlert=true -t fontFamily=monospace -t fontSize=14 -t 'theme={\"foreground\":\"#ebdbb2\",\"background\":\"#282828\",\"cursor\":\"#928374\",\"cursorAccent\":\"#fbf1c7\",\"selectionBackground\":\"#504945\",\"selectionForeground\":\"#fbf1c7\",\"black\":\"#282828\",\"red\":\"#cc241d\",\"green\":\"#98971a\",\"yellow\":\"#d79921\",\"blue\":\"#458588\",\"magenta\":\"#b16286\",\"cyan\":\"#689d6a\",\"white\":\"#a89984\",\"brightBlack\":\"#928374\",\"brightRed\":\"#fb4934\",\"brightGreen\":\"#b8bb26\",\"brightYellow\":\"#fabd2f\",\"brightBlue\":\"#83a598\",\"brightMagenta\":\"#d3869b\",\"brightCyan\":\"#8ec07c\",\"brightWhite\":\"#ebdbb2\"}'/" /etc/systemd/system/ttyd.service
fi
# We need to tweak a few things in order to manage our own graphical
# shell
#
# Environment variables cargo-culted from Google's
# /usr/local/bin/enable_gfxstream on 2025-12-09
#
if [[ -f /usr/share/vulkan/icd.d/gfxstream_vk_icd.json ]]; then
sudo mkdir -p /etc/environment.d
sudo tee /etc/environment.d/gfxstream_vk_icd.conf <<-EOF
#MESA_LOADER_DRIVER_OVERRIDE=zink
VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/gfxstream_vk_icd.json
MESA_VK_WSI_DEBUG=sw,linear
XWAYLAND_NO_GLAMOR=1
LIBGL_KOPPER_DRI2=1
# Reduce artifacting on Android VM
#
# FIXME: Check if this is still necessary after each Android release!
#
MESA_LOADER_DRIVER_OVERRIDE=kms_swrast
LIBGL_ALWAYS_SOFTWARE=1
EOF
fi
if [[ -f /etc/profile.d/activate_display.sh ]]; then
sudo mv /etc/profile.d/activate_display.sh /etc/profile.d/activate_display.sh.disabled
fi
if [[ -f "$HOME"/weston.env ]]; then
rm -f "$HOME"/weston.env
fi
sudo usermod -a -G render "$USER"
fi
# Clear out macOS settings that need to be set (or not set) explicitly
#
if [[ "$OS" == "Darwin" ]]; then
defaults delete kCFPreferencesAnyApplication AppleAccentColor 2>/dev/null || true
defaults delete kCFPreferencesAnyApplication AppleHighlightColor 2>/dev/null || true
defaults delete kCFPreferencesAnyApplication AppleIconAppearanceTintColor 2>/dev/null || true
fi
# Move files that we might overwrite out of the way
#
if [[ "$OS" == "Darwin" ]]; then
if [[ -e /etc/bashrc ]] && [[ ! -L /etc/bashrc ]]; then
sudo mv /etc/bashrc /etc/bashrc.before-nix
fi
if [[ -e /etc/pam.d/sudo_local ]] && [[ ! -L /etc/pam.d/sudo_local ]]; then
sudo mv /etc/pam.d/sudo_local /etc/pam.d/sudo_local.before-nix
fi
if [[ -e /etc/zprofile ]] && [[ ! -L /etc/zprofile ]]; then
sudo mv /etc/zprofile /etc/zprofile.before-nix
fi
if [[ -e /etc/zshenv ]] && [[ ! -L /etc/zshenv ]]; then
sudo mv /etc/zshenv /etc/zshenv.before-nix
fi
if [[ -e /etc/zshrc ]] && [[ ! -L /etc/zshrc ]]; then
sudo mv /etc/zshrc /etc/zshrc.before-nix
fi
fi
if [[ -e "$HOME"/.bashrc ]] && [[ ! -L "$HOME"/.bashrc ]]; then
mv "$HOME"/.bashrc "$HOME"/.bashrc.before-nix
fi
if [[ -e "$HOME"/.claude/CLAUDE.md ]] && [[ ! -L "$HOME"/.claude/CLAUDE.md ]]; then
mv "$HOME"/.claude/CLAUDE.md "$HOME"/.claude/CLAUDE.md.before-nix
fi
if [[ -e "$HOME"/.claude/settings.json ]] && [[ ! -L "$HOME"/.claude/settings.json ]]; then
mv "$HOME"/.claude/settings.json "$HOME"/.claude/settings.json.before-nix
fi
if [[ -e "$HOME"/.profile ]] && [[ ! -L "$HOME"/.profile ]]; then
mv "$HOME"/.profile "$HOME"/.profile.before-nix
fi
# Build configuration
#
if [[ "$OS" == "Darwin" ]]; then
(
cd "$HOME/.config/nix"
sudo -H nix run nix-darwin -- switch --flake .#macos
)
else
(
cd "$HOME/.config/nix"
dbus-run-session nix run home-manager/master -- switch --flake .#debian
)
fi
# Update runtime environment
#
unset __ETC_PROFILE_NIX_SOURCED
source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
# shellcheck disable=SC1091
source "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
# Run GPU setup for nixpkgs/home-manager
#
if [[ "$OS" == "Linux" ]]; then
sudo "$(which non-nixos-gpu-setup)"
fi
# Set up XDG user directories
#
if [[ "$XDG_DOCUMENTS_DIR" == /mnt/shared/Documents ]]; then
ln -sfT /mnt/shared/Documents "$HOME/Documents"
else
mkdir -p "$XDG_DOCUMENTS_DIR"
fi
mkdir -p "$XDG_DESKTOP_DIR"
mkdir -p "$XDG_DOWNLOAD_DIR"
if [[ "$XDG_MUSIC_DIR" == /mnt/shared/Music ]]; then
ln -sfT /mnt/shared/Music "$HOME/Music"
else
mkdir -p "$XDG_MUSIC_DIR"
fi
if [[ "$XDG_PICTURES_DIR" == /mnt/shared/Pictures ]]; then
ln -sfT /mnt/shared/Pictures "$HOME/Pictures"
else
mkdir -p "$XDG_PICTURES_DIR"
fi
mkdir -p "$XDG_PUBLICSHARE_DIR"
mkdir -p "$XDG_TEMPLATES_DIR"
if [[ "$XDG_VIDEOS_DIR" == /mnt/shared/Movies ]]; then
ln -sfT /mnt/shared/Movies "$HOME/Videos"
else
mkdir -p "$XDG_VIDEOS_DIR"
fi
# Claude Code pre-setup
#
mkdir -p "$XDG_CACHE_HOME"/claude-cli-nodejs
mkdir -p "$XDG_DATA_HOME"/claude
if [[ ! -f "$HOME"/.claude.json ]]; then
echo "{}" > "$HOME"/.claude.json
fi
# Calibre pre-setup
#
if [[ "$OS" == "Darwin" ]]; then
mkdir -p "$HOME/Library/Preferences/calibre"
mkdir -p "$HOME/Documents/Calibre"
fi
# Make sure that SSH is set up
#
chmod 700 "$HOME/.ssh"
find "$HOME/.ssh" -type d -exec chmod 700 "{}" \;
find "$HOME/.ssh" -type f -exec chmod 600 "{}" \;
if [[ $(find "$HOME/.ssh" -mindepth 1 -maxdepth 1 -type f -iname "id_ed25519" 2>/dev/null | wc -l) -eq 0 ]]; then
ssh-keygen -C "Nathan Acks <nathan.acks@cardboard-iguana.com> ($(date)) [$USER@$(hostname)]" -f "$HOME"/.ssh/id_ed25519 -t ed25519
echo ""
echo "-------------------"
echo "New SSH key created"
echo "-------------------"
echo ""
cat "$HOME"/.ssh/id_ed25519.pub
echo ""
echo "You must add the public SSH key displayed above to GitHub (as BOTH an"
echo "authentication AND signing key) before continuing."
echo ""
read -rs -n 1 -p "Press any key to continue once this step is complete."
echo ""
fi
# Install Helix grammars
#
# NOTE: This must be done *after* git is fully setup!
#
hx -g fetch
hx -g build
# Check out a few useful code repositories
#
mkdir -p "$HOME"/Projects
(
cd "$HOME"/Projects || exit 1
if [[ ! -d hackenv ]]; then
git clone --recurse-submodules \
git@github.com:cardboard-iguana/hackenv.git
fi
if [[ ! -d smart-contracts-hacking ]]; then
git clone --recurse-submodules \
git@github.com:cardboard-iguana/smart-contracts-hacking.git
fi
if [[ ! -d resume ]]; then
git clone --recurse-submodules \
git@github.com:necopinus/resume.git
fi
if [[ ! -d website-theme ]]; then
git clone --recurse-submodules \
git@github.com:necopinus/website-theme.git
fi
if [[ ! -d backups ]]; then
git clone --recurse-submodules \
git@github.com:The-Yak-Collective/backups.git
fi
if [[ ! -d GPTDiscord ]]; then
git clone --recurse-submodules \
git@github.com:The-Yak-Collective/GPTDiscord.git
fi
if [[ ! -d yakcollective ]]; then
git clone --recurse-submodules \
git@github.com:The-Yak-Collective/yakcollective.git
fi
if [[ ! -d cardboard-iguana.com ]]; then
git clone --recurse-submodules \
git@github.com:cardboard-iguana/cardboard-iguana.com.git
fi
if [[ ! -d chateaumaxmin.info ]]; then
git clone --recurse-submodules \
git@github.com:necopinus/chateaumaxmin.info.git
fi
if [[ ! -d delphi-strategy.com ]]; then
git clone --recurse-submodules \
git@github.com:necopinus/delphi-strategy.com.git
fi
if [[ ! -d digital-orrery.com ]]; then
git clone --recurse-submodules \
git@github.com:necopinus/digital-orrery.com.git
fi
if [[ ! -d necopinus.xyz ]]; then
git clone --recurse-submodules \
git@github.com:necopinus/necopinus.xyz.git
fi
if [[ ! -d quartz ]]; then
git clone --recurse-submodules \
https://github.com/jackyzha0/quartz.git
fi
if [[ ! -d twitter-archive-parser ]]; then
git clone --recurse-submodules \
https://github.com/timhutton/twitter-archive-parser.git
fi
)
# A reboot is STRONGLY recommended
#
echo ""
echo "Configuration complete!"
echo ""
echo "To finish setup you MUST restart the system NOW."