A simple rust binary to facilitate creating new jj workspaces when using nix direnv
README.md

newenv #

newenv deterministically primes nix-direnv for an already-created Jujutsu workspace. It is intended to run after jj workspace add and before Herdr launches Pi, so the first agent process and its children can use nix-direnv's cached development environment.

Requirements #

  • jj
  • direnv
  • nix-direnv configured for use flake

Usage #

newenv [WORKSPACE]

WORKSPACE is optional and defaults to the current directory. It may name the workspace root or a directory inside it. newenv asks jj workspace root for the canonical workspace root and fails if the path does not belong to an existing Jujutsu workspace.

The command is non-interactive and performs these steps in order:

  1. If the workspace has no flake.nix, print a skip message and exit successfully.
  2. Preserve an existing regular .envrc exactly. If the new workspace has no .envrc, locate the repository's main JJ workspace and copy its regular .envrc, including its permissions. This supports repository-specific .envrc files that are intentionally ignored and therefore absent from a new JJ workspace. newenv never overwrites an existing path or synthesizes generic .envrc contents; it fails if the main workspace has no .envrc to copy.
  3. Run direnv allow with the workspace as the process working directory.
  4. Eagerly load the environment with direnv exec <absolute-workspace> true, also from the workspace directory. Commands are spawned directly; no interpolated shell command is used.
  5. Verify that the workspace's top-level .direnv contains both a flake-profile* profile entry and a regular flake-profile*.rc cached environment file. A missing cache is reported as a nix-direnv configuration error instead of repeatedly evaluating the flake.

On success, Herdr can launch Pi through the cached environment, for example:

cd "$workspace" && exec direnv exec "$workspace" pi

Exit statuses #

  • 0: prepared successfully, skipped because there is no flake.nix, or displayed help/version
  • 1: workspace validation, filesystem, subprocess, or cache verification failed
  • 2: invalid command-line usage

Use newenv --help for the concise command synopsis.

Development #

The flake provides a Crane-based build, Clippy check, formatter check, and development shell.

direnv allow
direnv exec . cargo fmt --check
direnv exec . cargo test
direnv exec . cargo clippy --all-targets -- --deny warnings
nix flake check