- Rust 95%
- Nix 5%
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 #
jjdirenv- 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:
- If the workspace has no
flake.nix, print a skip message and exit successfully. - Preserve an existing regular
.envrcexactly. 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.envrcfiles that are intentionally ignored and therefore absent from a new JJ workspace.newenvnever overwrites an existing path or synthesizes generic.envrccontents; it fails if the main workspace has no.envrcto copy. - Run
direnv allowwith the workspace as the process working directory. - 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. - Verify that the workspace's top-level
.direnvcontains both aflake-profile*profile entry and a regularflake-profile*.rccached 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 noflake.nix, or displayed help/version1: workspace validation, filesystem, subprocess, or cache verification failed2: 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