Run stack with nix enabled in pure nix-shell

I’m trying to run stack in a pure nix-shell. When I do this i get the error

error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I), at (string):1:14

I think stack wants to know where to find the nixpkgs and in a pure shell we don’t want to depend on them. But I don’t use them in my stack.nix file. I use paths provided by niv. So stack shouldn’t need the nix search path.

Stack has its own Nix Integration which is used to for example install the appropriate compiler for the used resolver. This most likely relies on building haskell.compile.ghc<version> from <nixpkgs> which it tries to look up via NIX_PATHnix-shell --pure unsets that particular environment variable of course, so that’ll break.

You’ll have to check the stack manual how to work around this, most likely by turning of the integration altogether.

https://github.com/input-output-hk/haskell.nix/issues/689

I fixed this by adding

nix:
  path: [ nixpkgs=. ]

to stack.yaml
in the directory i have this default.nix

{ sources ? import ../nix/sources.nix
, pkgs ? import ../nix/pinned.nix { inherit sources;}}:

pkgs.nixpkgs