Skip to content

Add option to "nix shell" command to set env variables #10338

@rblrblrblrbl

Description

@rblrblrblrbl

Is your feature request related to a problem? Please describe.
From the "nix shell" manpages, we have the capability to alter the env variables of upcoming new shell via various options (--unset, --ignore-environment, --keep). That's fine if we want to narrow the environment variables, but what if we want to set/expand it ?

Describe the solution you'd like
An additional option to set an env variable in the created shell, for example a "--set var=value" option . This would be usefull when nix shell is executed from a script shebang where the workaround described below doesn't work.

Describe alternatives you've considered
If not executed via a script shebang, we can set the env var while running the command:

$ VAR1=value1 VAR2=value2 nix shell nixpkgs#tree
$ which tree; echo $VAR1
/nix/store/y9x314ap02i1s01ggkh4nmm54ks2ly5d-tree-2.1.1/bin/tree
value1

However this doesn't work vai script shebang.

Additional context
If you have other workarounds or if I missed an already existing option, please notify me,

Priorities
Due to the available workaround, it reduces the criticity of this request. However, such capability might be a good thing to improve Nix shebang usage

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request or proposalgood first issueQuick win for first-time contributorsidea approvedThe given proposal has been discussed and approved by the Nix team. An implementation is welcome.new-cliRelating to the "nix" commandnix-shellnix-shell, nix develop, nix print-dev-env, etc

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions