Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A safer inNixShell #3147

Closed
roberth opened this issue Oct 13, 2019 · 1 comment · Fixed by #3168
Closed

A safer inNixShell #3147

roberth opened this issue Oct 13, 2019 · 1 comment · Fixed by #3168

Comments

@roberth
Copy link
Member

roberth commented Oct 13, 2019

Nix sets IN_NIX_SHELL so that Nix expressions and scripts can do something else when they are requested for a nix-shell. This works well when only one derivation does this, but, because it is a global variable, dependencies of the shell derivation will respond to this too.

This has caused unexpected behavior on countless occasions.

For the usual goal of dual-purposing a default.nix, you only want to influence the invocation of default.nix itself. It seems the we're in luck, because we do actually have a mechanism for that: autoCallFunction.

I propose to change nix-shell to always add the effect of --arg inNixShell true.
This way, Nix expressions change their behavior based on a variable that isn't forced into dependencies. It will allow Nixpkgs to migrate away from the environment variable and put an end to those impure surprises.

Refs #2797, NixOS/nixpkgs#9438
Another broken use case is extending haskellPackages with cabal2nix generated files.

@matthewbauer
Copy link
Member

matthewbauer commented Oct 14, 2019

Getting rid of "IN_NIX_SHELL" usages is definitely good, but having different behavior for "nix-shell" and "nix-build" is itself an impurity (or at least a surprising inconsistency). It would be nice if we could rework things to not require knowing whether we are in a nix-shell or not. So perhaps this would work as a fix for now provided pureEval = false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants