8000 pynix: add a develop command that mimics nix develop · Issue #87 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

pynix: add a develop command that mimics nix develop #87

Closed as not planned
Closed as not planned

Description

@Lillecarl

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:

  1. Read the .drv.
  2. Replace builder and args with Nix's own get-env.sh, which the binary
    embeds as get-env.sh.gen.hh.
  3. Erase outputChecks, allowedReferences, allowedRequisites,
    disallowedReferences and disallowedRequisites, because the printing
    derivation would fail them.
  4. Rename the derivation to <name>-env, and clear each output path.
  5. Write the modified derivation back to the store, and build it.
  6. Read the JSON that get-env.sh wrote. It carries bashFunctions,
    variables, each tagged exported, var, array or associative, and,
    for a __structuredAttrs derivation, the .attrs.json and .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.sh come 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 from drvAttrs with a different builder
    would avoid the new capability. Measure that against a real devShell
    before choosing it: it changes what Nix hashes, so the result is a different
    store path than nix develop produces, and the two commands would then
    disagree about what is cached.

Scope

In:

  • pynix develop, which takes the same target options as pynix build
    (file_option, attr_option, flake_option from pynix/target.py), and
    defaults to devShells.<system>.default as nix develop does.
  • --command and -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, --redirect and the nix develop flags that serve a
    development profile. They are a separate feature on top of this one.
  • Any shell other than bash. nix develop starts bash, and matching it is the
    subject.

Acceptance criteria

  • pynix print-dev-env --json and nix print-dev-env --json agree on the
    variables of a real devShell, for a fixture flake in this repository.
  • pynix develop -c env reports IN_NIX_SHELL=impure, and the PATH carries
    the inputs of the shell.
  • A __structuredAttrs = true derivation works, and the test says so. That is
    the branch most likely to be forgotten, because a plain mkDerivation never
    reaches it.
  • The new nanopynix capability is public, is documented, and has its own
    tests on both engines. A capability that only pynix can 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 -c form.
  • tests/nanopynix/: the write-a-derivation capability, on inproc and rpc,
    including the round trip read_derivation -> modify -> write -> read again.
  • A __structuredAttrs case in both.

Activity

  1. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    Duplicate of #88, which the same /fork run filed three minutes later. #88
    names 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.

  2. added
    source: nanopynix
    on Oct 19, 2026
  3. 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