Skip to content

Instantly share code, notes, and snippets.

@mantono
Last active August 7, 2026 10:08
Show Gist options
  • Select an option

  • Save mantono/295ee72cbc54a3abc8dc77977d5d97ff to your computer and use it in GitHub Desktop.

Select an option

Save mantono/295ee72cbc54a3abc8dc77977d5d97ff to your computer and use it in GitHub Desktop.
System bootstrap
#!/bin/sh
install_nix() {
echo "Nix is not installed; installing it now..."
installer="$(mktemp)" || return 1
if ! curl --fail --location --silent --show-error https://nixos.org/nix/install --output "$installer"; then
rm -f "$installer"
return 1
fi
if ! sh "$installer" --daemon; then
rm -f "$installer"
return 1
fi
rm -f "$installer"
export PATH="/nix/var/nix/profiles/default/bin:$PATH"
}
if ! command -v nix-shell >/dev/null 2>&1; then
install_nix || exit 1
fi
nix-shell --packages git stow gnumake --run '
set -euo pipefail
# Clone a repository if needed, then optionally run a setup command in it.
# Usage: setup_repository REPOSITORY DESTINATION [COMMAND...]
setup_repository() {
repository="$1"
destination="$2"
shift 2
test -d "$destination" || git clone "$repository" "$destination"
test "$#" -eq 0 || (cd "$destination" && "$@")
}
if test -e /etc/NIXOS; then
setup_repository git@github.com:mantono/system-config.git "${HOME}/system-config" make switch
fi
setup_repository git@github.com:mantono/dotfiles.git "${HOME}/dotfiles" make
mkdir --parents "${HOME}/code/mantono"
setup_repository git@github.com:mantono/agents.git "${HOME}/code/mantono/agents"
echo -e "\nBootstrap completed"
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment