Bootstrap
Commands for bringing up a new Collective machine. The machine must already be registered in the flake, and you need its SSH private key.
Nix-on-Droid phone or tablet
- Install Nix-on-Droid and choose the flake bootstrap.
- Connect the Android Tailscale app, so the build can reach the binary caches.
- In Nix-on-Droid, run this, paste the machine's SSH private key when asked, then press Ctrl-D:
nix shell github:NixOS/nixpkgs/nixos-24.05#curl -c curl -fsSLo bootstrap-nod.sh \
-H 'Accept: application/vnd.github.raw' \
https://api.github.com/repos/harryaskham/collective-public/contents/scripts/bootstrap-nod.sh
bash bootstrap-nod.sh MACHINE
It installs the key, prints its public key, age recipient and app uid/gid, clones Collective, then builds and activates the machine with its own Nix and caches. Run it again to pull and rebuild; once activated, use cltv switch.
Until Cacophony is bootstrapped, activation warns that it is not starting caco; everything else runs. Then, in a new shell, bring up Cacophony:
~/collective/scripts/bootstrap-caco.sh
Activate a prebuilt generation
If the phone's bootstrap would compile for hours, activate a generation that a prebuild or CI has already built. Run the bootstrap first, so the key and checkout are in place (Ctrl-C once it prints Building activation package). Then give the generation's store path and a binary cache that holds it:
nix build --no-link GENERATION \
--option extra-substituters CACHE_URL \
--option extra-trusted-public-keys CACHE_KEY
GENERATION/activate
The generation must be built for this install's app uid/gid, which the bootstrap prints. Once it has activated, bring up Cacophony with ~/collective/scripts/bootstrap-caco.sh in a new shell; after that, cltv switch works as usual.
Windows devbox (NixOS on WSL)
In an elevated PowerShell on the Windows host. It asks for the hostname and the machine's SSH key, installs NixOS on WSL and switches it:
$h=@{"User-Agent"="collective-devbox-bootstrap";"Cache-Control"="no-cache"}; $r="https://api.github.com/repos/harryaskham/collective-public/git/ref/heads/main"; $s=(irm "${r}?nocache=$([guid]::NewGuid())" -Headers $h).object.sha; & ([scriptblock]::Create((irm "https://raw.githubusercontent.com/harryaskham/collective-public/$s/windows/bootstrap-devbox.ps1" -Headers $h))) -PublicCommit $s
On a Dev Box with a small C: (512 GB) and a big Q:, move the WSL disk to Q:\WSL\NixOS as soon as the distro exists, while it is still small (no elevation needed; it stops WSL, then restarts it), then resume the bootstrap below:
$h=@{"User-Agent"="collective-devbox";"Cache-Control"="no-cache"}; $s=(irm "https://api.github.com/repos/harryaskham/collective-public/git/ref/heads/main?nocache=$([guid]::NewGuid())" -Headers $h).object.sha; $p=Join-Path $env:TEMP "devbox-maintenance.ps1"; irm "https://raw.githubusercontent.com/harryaskham/collective-public/$s/windows/devbox-maintenance.ps1" -Headers $h -OutFile $p; & $p -Operation Move -Distro NixOS -TargetDrive Q
To resume an interrupted bootstrap without reinstalling the distro:
$h=@{"User-Agent"="collective-devbox-bootstrap";"Cache-Control"="no-cache"}; $r="https://api.github.com/repos/harryaskham/collective-public/git/ref/heads/main"; $s=(irm "${r}?nocache=$([guid]::NewGuid())" -Headers $h).object.sha; $p=Join-Path $env:TEMP "bootstrap-devbox.ps1"; irm "https://raw.githubusercontent.com/harryaskham/collective-public/$s/windows/bootstrap-devbox.ps1" -Headers $h -OutFile $p; & $p -PublicCommit $s -SkipWSLInstall
Then, inside NixOS on WSL, provision Cacophony:
~/collective/scripts/bootstrap-caco.sh
Devbox maintenance
Disk report and WSL disk compaction, in an elevated PowerShell (the dry run also works unelevated). Each run leaves a receipt under %LOCALAPPDATA%\devbox\maintenance:
$h=@{"User-Agent"="collective-devbox";"Cache-Control"="no-cache"}; $s=(irm "https://api.github.com/repos/harryaskham/collective-public/git/ref/heads/main?nocache=$([guid]::NewGuid())" -Headers $h).object.sha; $p=Join-Path $env:TEMP "devbox-maintenance.ps1"; irm "https://raw.githubusercontent.com/harryaskham/collective-public/$s/windows/devbox-maintenance.ps1" -Headers $h -OutFile $p
& $p -Distro NixOS -DryRun
& $p -Operation Compact -Distro NixOS
& $p -Operation Move -Distro NixOS -TargetDrive Q # VHD to Q:\WSL\NixOS; no elevation needed
From inside WSL, once devbox-windows-admin has installed the maintenance task: ~/collective/scripts/devbox-maintenance move (the session ends while WSL stops).
Grow the WSL disk to 1.5 TiB, after saving work in every WSL session:
$u="https://raw.githubusercontent.com/harryaskham/collective-public/main/windows/grow-devbox-vhd.ps1"; $p=Join-Path $env:TEMP "grow-devbox-vhd.ps1"; irm $u -OutFile $p; & $p -Distro NixOS
Linux VM on a Mac
On the macOS host, from its Collective checkout. The last step copies the host's Git identities, clones Collective in the guest, rebuilds it and brings up Tailscale; it is safe to re-run:
linux-vm seed MACHINE
linux-vm start MACHINE
scripts/bootstrap-macos-linux-vm.sh MACHINE
Any machine with Collective
Once a machine has a checkout and has switched once:
cltv switch # build and activate this machine
cltv switch --cached # activate the generation its prebuild cache published