Skip to content

Add flag --print-path to nix print-dev-env, expose getDerivationEnvironment in libcmd#15665

Closed
lisanna-dettwyler wants to merge 3 commits into
NixOS:masterfrom
lisanna-dettwyler:dev-env-path
Closed

Add flag --print-path to nix print-dev-env, expose getDerivationEnvironment in libcmd#15665
lisanna-dettwyler wants to merge 3 commits into
NixOS:masterfrom
lisanna-dettwyler:dev-env-path

Conversation

@lisanna-dettwyler

Copy link
Copy Markdown
Contributor

This new flag prints the store path of the shell environment rather than the contents. Use this new flag to add a garbage collection example in store-delete.md.

Also expose getDerivationEnvironment in libcmd, and in a new stubbed libcmd-c as nix_libcmd_get_derivation_environment. Additional bindings will probably be upstreamed by the cachix team in the future.

@domenkozar you should find this useful for devenv

Motivation

This new flag enables garbage collection of dev shells, which are not directly instantiated.

getDerivationEnvironment is useful for utilities like devenv to compute the same shell environment that nix develop does for a derivation.

Context

#15236
#7239


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions Bot added documentation new-cli Relating to the "nix" command c api Nix as a C library with a stable interface labels Apr 12, 2026
@lisanna-dettwyler lisanna-dettwyler changed the title Add flag --path to nix print-dev-env, expose getDerivationEnvironment in libcmd Add flag --path to nix print-dev-env, expose getDerivationEnvironment in libcmd Apr 12, 2026
@lisanna-dettwyler

Copy link
Copy Markdown
Contributor Author

@roberth what are the grammar conventions again for flags?

@roberth roberth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not a fan of nix develop, because it's too coupled with nixpkgs and everything.
I think the right direction would be to make shell environment and shell runners part of package expressions instead of continuing to "derive" them from derivations.

Context:

Comment thread src/libcmd-c/nix_api_develop.h Outdated
Comment thread src/nix/develop.cc Outdated
This prints the store path of the shell environment rather than the
contents. This enables garbage collection of dev shells, which are not
directly instantiated.

Signed-off-by: Lisanna Dettwyler <lisanna.dettwyler@gmail.com>
@lisanna-dettwyler lisanna-dettwyler changed the title Add flag --path to nix print-dev-env, expose getDerivationEnvironment in libcmd Add flag --print-path to nix print-dev-env, expose getDerivationEnvironment in libcmd Apr 12, 2026
Signed-off-by: Lisanna Dettwyler <lisanna.dettwyler@gmail.com>
Additionally adds a mostly stubbed libcmd-c library with just
nix_libcmd_get_legacy_shell_derivation_environment exposed. Additional
bindings will probably be upstreamed by the cachix team in the future.

This function is useful for utilities like devenv to compute the same
shell environment that `nix develop` does for a derivation.

Signed-off-by: Lisanna Dettwyler <lisanna.dettwyler@gmail.com>
@edolstra

edolstra commented Apr 13, 2026

Copy link
Copy Markdown
Member

Note that there already is nix develop --profile <profile> for saving a dev shell in a GC-safe way, and nix develop <profile> for re-entering it.

@Ericson2314

Copy link
Copy Markdown
Member

I agree with @roberth that nix_libcmd_get_derivation_environment would disincentivize migrating to #7501. Thank you for volunteering to tackle #7501 --- hopefully if that is done, then then need for all of this goes away, and the annoyance of downstream re-implementing the shell logic (status quo) incentivizes the migration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface documentation new-cli Relating to the "nix" command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants