Repository navigation
Description
What
pynix has build, eval, derivation, flake, repl, store,
path-info, log, osearch and lsp. It has no answer to nix develop,
which is the command a developer uses most.
Add one. This issue is mostly a bindings question, and not a CLI question,
and the evidence below says why.
How nix develop works
src/nix/develop.cc in Nix 2.34, 753 lines. The core is
getDerivationEnvironment (line 233), and it does this:
- Read the derivation of the target (
readDerivation). - Refuse it when the builder is not
bash(line 238). That refusal is
the contract, andpynixmust keep it. - Rewrite the derivation in memory: point
argsatget-env.sh, erase
outputChecksor the fourallowedReferences-style variables, erase and
rewritenamewith a-envsuffix, addget-env.shtoinputSrcs, and
turn each input-addressed output into aDeferredone. - Write the rewritten derivation back to the store, and build it.
- Read the JSON the builder wrote. It names each variable by kind --
exported, plain, array or associative -- plus the bash functions and, for
a structured-attrs derivation,.attrs.jsonand.attrs.sh. - Compose a bash startup file from that, and exec bash.
nix print-dev-env (line 718) is steps 1 to 5 with no shell. It is the whole
computation, and it prints it.
What nanopynix has, and the one thing it lacks
Have, and enough for steps 1 and 4:
| need | where |
|---|---|
| read a derivation | AsyncStore.read_derivation, nix_store.cpp:574 |
| add a file to the store | AsyncStore.add_to_store |
| build a derivation | AsyncStore.build_paths_with_results |
| a mutable derivation | nanopynix.Derivation, a betterproto message |
Lack, and it blocks step 4:
Nothing can write a derivation back to the store.
grep -rn "writeDerivation" nanopynix-bindings/src/ finds only the comments
about readDerivation being non-virtual before 2.32. There is no
write_derivation, and no add_derivation.
get-env.sh cannot be borrowed either. getEnvSh is a file-static
std::string in src/nix/develop.cc (line 222), compiled into the nix
command-line binary and present in no library. Nothing can bind it. pynix
must carry its own copy of the 158-line script, which is Nix's own code under
its licence.
The increments, in order
1. Store.write_derivation, in the bindings. One door, matching
read_derivation beside it. It is the whole blocker, it is useful on its own,
and tests/meta/test_consumer_surface.py already refuses a pynix that
reaches around the public API.
2. pynix print-dev-env. The whole computation with no shell, and the
only part that has an exact oracle: nix print-dev-env --json on the same
target must produce the same environment. Write that comparison as the test
and the hard part is finished and proven.
3. pynix develop. The shell, on top of 2. First increment takes a target
and --command, and nothing else.
Explicitly out of scope for the first increment
nix develop carries --profile, --redirect, --unpack, --configure,
--build, --install, --phase, and the MixEnvironment flags. Each is a
separate ask. Do not copy the room.
Acceptance criteria
pynix print-dev-env --json <target>agrees withnix print-dev-env --json
on the same target, for a plain derivation and for a structured-attrs one.pynix develop <target> --command <cmd>runs the command with that
environment, and exits with the command's status.- A derivation whose builder is not
bashis refused, with the reason. Store.write_derivationis justified in the ledger of
tests/meta/test_consumer_surface.pyifpynixreaches anything private.
Tests
- The
print-dev-envcomparison above, which is the acceptance test. - A derivation whose builder is not bash, and the refusal.
--commandand its exit status, including a non-zero one.- The rewritten derivation is a valid store object, and the original is
untouched.
Activity
Lillecarl commentedon Aug 4, 2026
The
/forkrun that filed this issue filed #87 as well, which covers the samesubject. This issue keeps the subject, because its title names the gap that
the work actually needs.
Two details from #87 are worth keeping here:
get-env.shin the binary, asget-env.sh.gen.hh. pynix carriesno such file, so it needs its own copy or its own equivalent.
Store.read_derivationexists on both engines (_core/_objects.py:284,protocols.py:399,nanopynix-bindings/src/nix_store.cpp:771), and theDerivationTypedDict ofnanopynix-bindings/src/store.pat:60alreadyholds
builder,args,env,outputs,input_srcs,input_drvsandstructured_attrs. The read half needs nothing new; the write half is thegap.
feat(pynix): add develop and print-dev-env
Lillecarl commentedon Aug 5, 2026
Implemented on
ci-developasa1132fa1. Three deviations from the plan above, each deliberate.1.
write_dev_shell_derivation, notStore.write_derivationIncrement 1 proposed one door beside
read_derivation. I did not add it. Two reasons, and the second is the stronger one.The three supported Nix versions disagree, in two places at once:
writeDerivation(Store &, drv, repair, readOnly)store->writeDerivation(drv)hashDerivationModulo+makeOutputPath, plus a separateXp::CaDerivationsbranchdrv.fillInOutputPaths(store)drv.env.erase(...)onlystructuredAttrs.erase("outputChecks")A Python implementation needs
write_derivation,fill_in_output_paths,hash_derivation_moduloandmake_output_pathall bound, plus a version branch inpynix.AGENTS.mdforbids that: no library version branches for 2.31, gate the test rather than the code.And with the rewrite in C++, the
nix::Derivationnever leaves C++.readDerivationproduces it, the rewrite mutates it,writeDerivationconsumes it. Nothing is converted to a Python dict and reconstructed, so there is no faithfulness question to test.write_derivationwould have to reconstruct every field -- five output variants, the nestedinputDrvsmap, structured attrs -- and prove the reconstruction lossless.write_derivationstays a reasonable door to open one day. It has no caller today.2.
--, not--commandEverything after
--is the command. clypi stops parsing there (arg_parser.py:18) and hands the tail back, sopynix develop -f . -- make -j4passes-j4through untouched. A pipeline belongs inside the command, as-- bash -c 'make | less'.One defect found on the way: clypi keeps the tail on the class and never clears it (
main.py:608), so a second parse in the same process with no--of its own reports the first one's tail.take_unparsedclears it. A one-parse-per-process command line would never reveal this.3. Both commands, not
print-dev-envfirstprint-dev-envis the oracle, so it is what the acceptance test drives.developis thin on top of it and shipped in the same commit.Acceptance
pynix print-dev-env --jsonagainstnix print-dev-env --jsonon the same target: 118 of 120 variables, all 98 bash functions and both structured attributes agree exactly, for a plain derivation and for a__structuredAttrs = trueone. The rendered bash agrees line for line after the same two.The two that differ, and why.
pynix/src/pynix/get-env.shis Nix's script vendored under LGPL-2.1-or-later with a provenance header, and that header is the only change:LINENO-- the header moves the dump 18 lines down the file.-frandom-seed=insideNIX_CFLAGS_COMPILE-- stdenv derives it from the output path, and the output path follows the derivation.Both are consequences of the header, which is a deliberate choice.
tests/pynix/test_develop.pynames them and asserts that nothing else differs.The other criteria: a non-bash builder is refused with Nix's own message;
-- <cmd>exits with the command's status, 42 included; the original derivation is byte-identical before and after.pynixreaches no private module of nanopynix, so the ledger intests/meta/test_consumer_surface.pyneeds no entry.Out of scope, as the issue says:
--profile,--redirect,--unpack,--configure,--build,--install,--phaseand theMixEnvironmentflags.feat(pynix): add develop and print-dev-env
feat(pynix): add develop and print-dev-env