Nixpkgs: pkgs.lib.inNixShell giving false positives

Created on 25 Aug 2015  路  8Comments  路  Source: NixOS/nixpkgs

I was deploying a haskell app with nix-shell -p nixopsUnstable using following command:

[nix-shell:~/dev/nixops-deployments/avokado]$ nixops deploy -d avokado-production -I `pwd`

and clearly haskell default.nix wanted to build .env because I was in nix-shell. Not really sure how to approach this, but just making sure we have an issue for it.

cc @peti

bug haskell

All 8 comments

Workaround is to clear $IN_NIX_SHELL.

I have no idea how to improve that situation from the Haskell/cabal2nix side, I'm afraid.

cabal2nix --shell generates those dual-use expressions that distinguish between builds and shell environments via pkgs.lib.inNixShell, and that mechanism is clearly flawed when trying to nix-build such an expression from inside of a nix-shell.

The only way to avoid that issue, IMHO, is to make sure that no --shell output is used for building outside of an interactive development environment, i.e. follow the 3-file-setup as described in the user manual at http://hydra.nixos.org/job/nixpkgs/trunk/manual/latest/download-by-type/doc/manual#how-to-create-nix-builds-for-your-own-private-haskell-packages.

Another would be for nixops and similar deployment apps to clear $IN_NIX_SHELL themselves

How about introduce another variable (eg: $EVAL_BY_NIX_SHELL)
and nix-shell should unset it after launched.

Closing as this is something that nixops should handle.

This hit me today too, nixops accidentally evaluating shellHook derivations instead of my actual contents. Is there a clean workaround by now?

@Zimmi48 and I have been discussing exactly this problem. In summary: we would like to use lib.inNixShell to tell whether the current expression is being evaluated by nix-shell (as opposed to nix build), but right now it (as advertised) only tells us that we're the child process of a nix-shell.

One solution might be to have some sort of lib.calledBy, which specifies which nix tool is doing the calling.

Are there any uses of inNixShell which take advantage of the current behaviour? I also ran into this problem today.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

domenkozar picture domenkozar  路  3Comments

tomberek picture tomberek  路  3Comments

rzetterberg picture rzetterberg  路  3Comments

matthiasbeyer picture matthiasbeyer  路  3Comments

grahamc picture grahamc  路  3Comments