Skip to main content

Script recipes

Some tools only ship a curl … | sh installer or need a source build. Script recipes cover them, safely.

42space recipe new mytool --version 1.2 # template, pre-filled with matching journal commands
$EDITOR ~/.config/42space/scripts/mytool.sh
42space recipe approve mytool # shows the script (or a diff), asks, then installs
42space recipe list

The script runs with sh -e in an empty scratch directory and gets:

VariableMeaning
$PREFIXinstall everything here; bin/ is exposed on PATH
$VERSIONthe version from the recipe
$WORKscratch directory, deleted afterwards
$CACHEmachine-local cache directory

Approval​

A script runs only if its exact sha256 is approved, and any edit needs a new approval. Approvals live in ~/.local/state/42space, outside the git-synced repo, so a pulled commit can never approve itself. One approval covers all your machines. Scripts that call sudo, su, pkexec or doas are refused.

Each script revision installs into its own directory, so a failing edit never destroys the last good install.

Example: nvm without curl | bash​

nvm's installer writes to ~/.nvm and edits your rc files. As a recipe it lives in goinfre instead, and expose.lazy defines a stub that loads nvm.sh on first use, so shells don't get slower:

~/.config/42space/tools.d/nvm.toml
name = "nvm"
version = "0.41.0"
strategy = "script"
script = "scripts/nvm.sh"

[expose.lazy]
nvm = "{prefix}/load.sh"

[expose.env]
NVM_DIR = "{cache}/nvm"
~/.config/42space/scripts/nvm.sh
git clone --quiet --depth 1 --branch "v$VERSION" https://github.com/nvm-sh/nvm.git "$WORK/nvm"
cp -R "$WORK/nvm/." "$PREFIX/" && rm -rf "$PREFIX/.git"
mkdir -p "$CACHE/nvm"
# nvm refuses to run with a global npm prefix; drop it only in shells that use nvm
printf 'unset NPM_CONFIG_PREFIX npm_config_prefix\n. "%s/nvm.sh"\n' "$PREFIX" > "$PREFIX/load.sh"