8000 pynix: add a develop command, which needs a way to write a derivation · Issue #88 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

pynix: add a develop command, which needs a way to write a derivation #88

Closed

Description

@Lillecarl

What

pynix has build, < 8000 code class="notranslate">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:

  1. Read the derivation of the target (readDerivation).
  2. Refuse it when the builder is not bash (line 238). That refusal is
    the contract, and pynix must keep it.
  3. Rewrite the derivation in memory: point args at get-env.sh, erase
    outputChecks or the four allowedReferences-style variables, erase and
    rewrite name with a -env suffix, add get-env.sh to inputSrcs, and
    turn each input-addressed output into a Deferred one.
  4. Write the rewritten derivation back to the store, and build it.
  5. 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.json and .attrs.sh.
  6. 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 with nix 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 bash is refused, with the reason.
  • Store.write_derivation is justified in the ledger of
    tests/meta/test_consumer_surface.py if pynix reaches anything private.

Tests

  • The print-dev-env comparison above, which is the acceptance test.
  • A derivation whose builder is not bash, and the refusal.
  • --command and its exit status, including a non-zero one.
  • The rewritten derivation is a valid store object, and the original is
    untouched.

Activity

  1. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    The /fork run that filed this issue filed #87 as well, which covers the same
    subject. This issue keeps the subject, because its title names the gap that
    the work actually needs.

    Two details from #87 are worth keeping here:

    • Nix embeds get-env.sh in the binary, as get-env.sh.gen.hh. pynix carries
      no such file, so it needs its own copy or its own equivalent.
    • Store.read_derivation exists on both engines (_core/_objects.py:284,
      protocols.py:399, nanopynix-bindings/src/nix_store.cpp:771), and the
      Derivation TypedDict of nanopynix-bindings/src/store.pat:60 already
      holds builder, args, env, outputs, input_srcs, input_drvs and
      structured_attrs. The read half needs nothing new; the write half is the
      gap.
  2. Lillecarl commented on Aug 5, 2026

    @Lillecarl
    ContributorAuthor

    Implemented on ci-develop as a1132fa1. Three deviations from the plan above, each deliberate.

    1. write_dev_shell_derivation, not Store.write_derivation

    Increment 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:

    2.31 2.34 / 2.35
    write free writeDerivation(Store &, drv, repair, readOnly) store->writeDerivation(drv)
    output paths hand-rolled hashDerivationModulo + makeOutputPath, plus a separate Xp::CaDerivations branch drv.fillInOutputPaths(store)
    checks erased four drv.env.erase(...) only also structuredAttrs.erase("outputChecks")

    A Python implementation needs write_derivation, fill_in_output_paths, hash_derivation_modulo and make_output_path all bound, plus a version branch in pynix. AGENTS.md forbids that: no library version branches for 2.31, gate the test rather than the code.

    And with the rewrite in C++, the nix::Derivation never leaves C++. readDerivation produces it, the rewrite mutates it, writeDerivation consumes it. Nothing is converted to a Python dict and reconstructed, so there is no faithfulness question to test. write_derivation would have to reconstruct every field -- five output variants, the nested inputDrvs map, structured attrs -- and prove the reconstruction lossless.

    write_derivation stays a reasonable door to open one day. It has no caller today.

    2. --, not --command

    Everything after -- is the command. clypi stops parsing there (arg_parser.py:18) and hands the tail back, so pynix develop -f . -- make -j4 passes -j4 through 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_unparsed clears it. A one-parse-per-process command line would never reveal this.

    3. Both commands, not print-dev-env first

    print-dev-env is the oracle, so it is what the acceptance test drives. develop is thin on top of it and shipped in the same commit.

    Acceptance

    pynix print-dev-env --json against nix print-dev-env --json on 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 = true one. The rendered bash agrees line for line after the same two.

    The two that differ, and why. pynix/src/pynix/get-env.sh is 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= inside NIX_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.py names 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. pynix reaches no private module of nanopynix, so the ledger in tests/meta/test_consumer_surface.py needs no entry.

    Out of scope, as the issue says: --profile, --redirect, --unpack, --configure, --build, --install, --phase and the MixEnvironment flags.

  3. added
    source: nanopynix
    on Oct 19, 2026
  4. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0