nix: delegate devShell setup to package passthru hooks

- use inputsFrom to inherit build inputs from packages
- concat passthru.devShellHook from each package
This commit is contained in:
Ari Lotter 2026-04-09 15:30:29 -04:00
parent 31b2c12f0f
commit 21afb3fa3c

View file

@ -1,49 +1,26 @@
# nix/devShell.nix — Fast dev shell with stamp-file optimization # nix/devShell.nix — Dev shell that delegates setup to each package
#
# Each package in inputsFrom exposes passthru.devShellHook — a bash snippet
# with stamp-checked setup logic. This file collects and runs them all.
{ inputs, ... }: { { inputs, ... }: {
perSystem = { pkgs, ... }: perSystem = { pkgs, system, ... }:
let let
python = pkgs.python311; hermes-agent = inputs.self.packages.${system}.default;
hermes-tui = inputs.self.packages.${system}.tui;
packages = [ hermes-agent hermes-tui ];
in { in {
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
inputsFrom = packages;
packages = with pkgs; [ packages = with pkgs; [
python uv nodejs_20 ripgrep git openssh ffmpeg python311 uv nodejs_22 ripgrep git openssh ffmpeg
]; ];
shellHook = '' shellHook = let
hooks = map (p: p.passthru.devShellHook or "") packages;
combined = pkgs.lib.concatStringsSep "\n" (builtins.filter (h: h != "") hooks);
in ''
echo "Hermes Agent dev shell" echo "Hermes Agent dev shell"
${combined}
# Composite stamp: changes when nix python or uv change
STAMP_VALUE="${python}:${pkgs.uv}"
STAMP_FILE=".venv/.nix-stamp"
# Create venv if missing
if [ ! -d .venv ]; then
echo "Creating Python 3.11 venv..."
uv venv .venv --python ${python}/bin/python3
fi
source .venv/bin/activate
# Only install if stamp is stale or missing
if [ ! -f "$STAMP_FILE" ] || [ "$(cat "$STAMP_FILE")" != "$STAMP_VALUE" ]; then
echo "Installing Python dependencies..."
uv pip install -e ".[all]"
if [ -d mini-swe-agent ]; then
uv pip install -e ./mini-swe-agent 2>/dev/null || true
fi
if [ -d tinker-atropos ]; then
uv pip install -e ./tinker-atropos 2>/dev/null || true
fi
# Install npm deps
if [ -f package.json ] && [ ! -d node_modules ]; then
echo "Installing npm dependencies..."
npm install
fi
echo "$STAMP_VALUE" > "$STAMP_FILE"
fi
echo "Ready. Run 'hermes' to start." echo "Ready. Run 'hermes' to start."
''; '';
}; };