From 60cd24cecc400d4381f5e6243940b5d0e760e4f9 Mon Sep 17 00:00:00 2001 From: sommerfeld Date: Wed, 13 May 2026 13:43:42 +0100 Subject: feat(remote-dev): add Nix Home-Manager flake for Ubuntu 22 VM dev env New remote-dev/ subdir with a Home-Manager flake that provisions a headless dev environment on a remote Ubuntu 22.04 VM accessed via SSH. Shares nvim, zellij, zsh, direnv, and ghostty configs from the same dotfiles repo via mkOutOfStoreSymlink (no rebuilds on config edits). CLI tool set mirrors the dev-tool subset of meta/base.txt; sysadmin tools (procs, gdu, duf), lazygit, and node/yarn (only needed for markdown-preview on GUI hosts) are excluded. bootstrap.sh is one-shot: installs Nix via Determinate Systems installer, clones the repo to ~/.local/share/dotfiles, runs home-manager switch, and chshes to the nix-store zsh. dot_config/zsh/dot_zshrc loses its hardcoded Arch plugin/git-prompt paths in favour of a fallback search: Arch path first, then $HOME/.nix-profile/share/. Same file works on host and VM. .chezmoiignore: exclude remote-dev/ from chezmoi deploy on the host. --- remote-dev/bootstrap.sh | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 remote-dev/bootstrap.sh (limited to 'remote-dev/bootstrap.sh') diff --git a/remote-dev/bootstrap.sh b/remote-dev/bootstrap.sh new file mode 100755 index 0000000..c1e95df --- /dev/null +++ b/remote-dev/bootstrap.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env sh +# Bootstrap a headless dev environment on a fresh Ubuntu 22.04 VM. +# Idempotent: safe to re-run. +# +# curl -fsSL https://raw.githubusercontent.com//dotfiles/master/remote-dev/bootstrap.sh | sh +# +# Steps: +# 1. Install Nix (Determinate Systems installer, multi-user). +# 2. Clone (or fast-forward) the dotfiles repo to ~/.local/share/dotfiles. +# 3. Run `home-manager switch --flake .../remote-dev#vm`. +# 4. Add Nix-store zsh to /etc/shells and chsh the user. +# +# Environment overrides: +# DOTFILES_REPO Git URL (default: https://github.com/ruifm/dotfiles) +# DOTFILES_REF Branch/tag/sha (default: master) +# DOTFILES_DIR Checkout path (default: $HOME/.local/share/dotfiles) + +set -eu + +REPO="${DOTFILES_REPO:-https://github.com/ruifm/dotfiles}" +REF="${DOTFILES_REF:-master}" +DIR="${DOTFILES_DIR:-$HOME/.local/share/dotfiles}" + +log() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } +err() { printf '\033[1;31m==>\033[0m %s\n' "$*" >&2; } + +# ── 1. Nix ──────────────────────────────────────────────────────────────────── +if ! command -v nix >/dev/null 2>&1; then + log "Installing Nix (Determinate Systems installer)…" + curl --proto '=https' --tlsv1.2 -sSf -L \ + https://install.determinate.systems/nix | + sh -s -- install linux --no-confirm +else + log "Nix already installed, skipping installer." +fi + +# Source nix env for the rest of this script (installer writes +# /etc/profile.d/nix.sh but the current shell hasn't sourced it). +if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then + # shellcheck disable=SC1091 + . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh +fi + +# ── 2. Repo checkout ───────────────────────────────────────────────────────── +if ! command -v git >/dev/null 2>&1; then + log "Bootstrapping git via nix profile…" + nix profile install nixpkgs#git +fi + +if [ -d "$DIR/.git" ]; then + log "Updating existing checkout at $DIR…" + git -C "$DIR" fetch origin "$REF" + git -C "$DIR" checkout "$REF" + git -C "$DIR" pull --ff-only +else + log "Cloning $REPO ($REF) → $DIR…" + mkdir -p "$(dirname "$DIR")" + git clone --branch "$REF" "$REPO" "$DIR" +fi + +# ── 3. Home-Manager switch ─────────────────────────────────────────────────── +log "Running home-manager switch (this can take a while on first run)…" +nix --extra-experimental-features 'nix-command flakes' \ + run home-manager/master -- \ + switch --impure --flake "$DIR/remote-dev#vm" -b backup + +# ── 4. chsh to nix-store zsh ───────────────────────────────────────────────── +NIX_ZSH="$HOME/.nix-profile/bin/zsh" +if [ -x "$NIX_ZSH" ]; then + if ! grep -qxF "$NIX_ZSH" /etc/shells 2>/dev/null; then + log "Appending $NIX_ZSH to /etc/shells (requires sudo)…" + echo "$NIX_ZSH" | sudo tee -a /etc/shells >/dev/null + fi + current_shell="$(getent passwd "$USER" | cut -d: -f7)" + if [ "$current_shell" != "$NIX_ZSH" ]; then + log "Changing login shell to $NIX_ZSH (requires sudo)…" + sudo chsh -s "$NIX_ZSH" "$USER" + fi +fi + +log "Done. Log out and back in for the new shell to take effect." +log "Then run 'nvim' once to let it fetch plugins on first launch." -- cgit v1.3.1