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

Environment variable equivalent for --nix #3980

Closed
CMCDragonkai opened this issue Apr 21, 2018 · 8 comments
Closed

Environment variable equivalent for --nix #3980

CMCDragonkai opened this issue Apr 21, 2018 · 8 comments

Comments

@CMCDragonkai
Copy link

Just a feature suggestion.

I know there's the --nix flag and the nix setting on the stack.yaml. However I'd prefer there to be a sort of environment variable to utilise instead. Something like STACK_USE_NIX=1.

The reason is that I don't want to force nix onto non-nix users by setting it on the stack.yaml and using an alias doesn't get inherited by shell scripts: alias stack='\stack --nix'.

@chris-martin
Copy link
Contributor

You can also put this into ~/.stack/config.yaml:

nix:
  enable: true

@CMCDragonkai
Copy link
Author

CMCDragonkai commented May 3, 2018 via email

@CMCDragonkai
Copy link
Author

CMCDragonkai commented May 5, 2018

This is now available inside Nix 2.0. Stack just needs to check this variable:

nix-shell now sets the IN_NIX_SHELL environment variable during evaluation and in the shell itself. This can be used to perform different actions depending on whether you’re in a Nix shell or in a regular build. Nixpkgs provides lib.inNixShell to check this variable during evaluation.

@enolan
Copy link
Contributor

enolan commented May 12, 2018

That's set when you're inside nix-shell, not just any shell on NixOS. I think a reasonable default is to check whether the host OS is NixOS by checking whether /run/current-system/nixos-version exists. Overridden by config.yaml and the command line --nix/--no-nix.

Alternatively, it could check whether /nix exists, which would include people running MacOS and other Linux distros that have installed Nix as well. I think the default expectation of those people is Stack works the same whether you install Nix or not, so my preference would be to not do that.

@CMCDragonkai
Copy link
Author

CMCDragonkai commented Jul 4, 2018

I thought this PR #3938 would bring in automatic nix integration without the explicit --nix flag. But I tried the recent 1.7.1 release, and it still required --nix to work. Or maybe that PR did not make it into 1.7.1? I'm not how to check.

Actually I checked the commit: a88aa5a

It indicates that the commit did make it into 1.7.1, so how come I still need --nix when using stack inside nix-shell. Here's my shell.nix:

{
  pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs-channels/archive/be1461fc0ab29c45c69e7b2c2097c887750e4fe0.tar.gz) {}
}:
  with pkgs;
  haskell.lib.buildStackProject {
    name = "stack-test";
  }

Then run stack --version and try using stack ghci on a simple project. It will say:

> stack ghci
/nix/store/szdi35clpzj13c8dhfzh55fj6hk0z8j6-glibc-2.27-bin/bin/ldconfig: Can't open cache file /nix/store/83lrbvbmxrgv7iz49mgd42yvhi473xp6-glibc-2.27/etc/ld.so.cache
: No such file or directory
I don't know how to install GHC on your system configuration, please install manually

Then stack --nix ghci ends up working.

@snoyberg
Copy link
Contributor

snoyberg commented Apr 2, 2019

What are the contents of your /etc/os-release file?

@CMCDragonkai
Copy link
Author

I'm not currently using stack anymore because Nix + Cabal is sufficient for now.

@snoyberg
Copy link
Contributor

snoyberg commented Apr 2, 2019

Understood closing

@snoyberg snoyberg closed this as completed Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants