Repository navigation
Description
What
Add pynix develop, which does what nix develop does: it enters a shell that
carries the build environment of a derivation.
pynix/src/pynix/__init__.py:39 lists eleven subcommands, and none of them
gives a developer a shell. nix develop is the command a Nix user reaches for
most often, so pynix cannot replace the CLI without it.
How nix develop really works, and why that matters here
It does not build the derivation. It builds a different derivation, whose
only job is to print the environment. getDerivationEnvironment
(src/nix/develop.cc:233 of Nix 2.34) does this:
- Read the
.drv. - Replace
builderandargswith Nix's ownget-env.sh, which the binary
embeds asget-env.sh.gen.hh. - Erase
outputChecks,allowedReferences,allowedRequisites,
disallowedReferencesanddisallowedRequisites, because the printing
derivation would fail them. - Rename the derivation to
<name>-env, and clear each output path. - Write the modified derivation back to the store, and build it.
- Read the JSON that
get-env.shwrote. It carriesbashFunctions,
variables, each taggedexported,var,arrayorassociative, and,
for a__structuredAttrsderivation, the.attrs.jsonand.attrs.sh
contents.
Then it writes an rc file that restores all of that, and execs bash.
The capability nanopynix does not have
Step 5 is the gap, and it is a nanopynix gap rather than a pynix one.
Store.read_derivation exists on both engines
(_core/_objects.py:284, protocols.py:399, and the binding at
nanopynix-bindings/src/nix_store.cpp:771). It returns the Derivation
TypedDict of nanopynix-bindings/src/store.pat:60, which already holds every
field this work needs: builder, args, env, outputs, input_srcs,
input_drvs and structured_attrs.
Nothing writes one back. There is no write_derivation, and
add_to_store takes a filesystem path rather than a derivation.
CLAUDE.md decides where that goes: pynix depends on the public API of
nanopynix, and a capability of general use belongs in nanopynix. Writing a
derivation to the store is of general use, so it lands in nanopynix and
pynix develop consumes it.
Two questions to answer before writing code
- Where does
get-env.shcome from? Nix embeds its own copy at compile
time, and this repository has no equivalent. Either carry a copy, which then
drifts from upstream, or read it from the Nix source that the flake already
pins. Say which, and why. - Does the modified derivation have to be written at all? An expression
that rebuilds the derivation fromdrvAttrswith a differentbuilder
would avoid the new capability. Measure that against a realdevShell
before choosing it: it changes what Nix hashes, so the result is a different
store path thannix developproduces, and the two commands would then
disagree about what is cached.
Scope
In:
pynix develop, which takes the same target options aspynix build
(file_option,attr_option,flake_optionfrompynix/target.py), and
defaults todevShells.<system>.defaultasnix developdoes.--commandand-c, which run one command in that environment rather than
starting a shell.pynix print-dev-env, with--json. It is the same work without the shell,
and it is what a test can assert on.- The nanopynix capability that step 5 needs.
Out:
--profile,--redirectand thenix developflags that serve a
development profile. They are a separate feature on top of this one.- Any shell other than bash.
nix developstarts bash, and matching it is the
subject.
Acceptance criteria
pynix print-dev-env --jsonandnix print-dev-env --jsonagree on the
variables of a realdevShell, for a fixture flake in this repository.pynix develop -c envreportsIN_NIX_SHELL=impure, and thePATHcarries
the inputs of the shell.- A
__structuredAttrs = truederivation works, and the test says so. That is
the branch most likely to be forgotten, because a plainmkDerivationnever
reaches it. - The new nanopynix capability is public, is documented, and has its own
tests on both engines. A capability that onlypynixcan reach is the rule
this repository already refuses.
Tests
tests/pynix/test_develop.py: the agreement test above, against a checked-in
fixture flake, and the-cform.tests/nanopynix/: the write-a-derivation capability, on inproc and rpc,
including the round tripread_derivation-> modify -> write -> read again.- A
__structuredAttrscase in both.
Activity
Lillecarl commentedon Aug 4, 2026
Duplicate of #88, which the same
/forkrun filed three minutes later. #88names the blocker in its title: the gap is a way to write a derivation back to
the store, and it is a nanopynix gap rather than a pynix one. The details
above are now on #88.