Running nix-build inside of nix-shell produces an ASCII text file instead of result folder

Im using the following default.nix for a Haskell project:

let
  pkgs = import <nixpkgs> { };
in
  pkgs.haskellPackages.developPackage {
    root = ./.;
    modifier = drv:
      pkgs.haskell.lib.addBuildTools drv (with pkgs.haskellPackages;
        [ cabal-install
          ghcid
        ]);
  }

As described here Nix recipes for Haskellers – Sridhar Ratnakumar or mhwombat/nix-for-numbskulls (github.com).

All would be fine. I can run nix-build or nix-shell without problems. But if I run nix-build inside of nix-shell, nix-build will not produce a result folder but a result ASCII text file.

And because I use .envrc with use nix to load the nix file and have all the dev dependencies, nix-shell is started and nix-build will no more work (produce ASCII text file instead of folder).

Extracting the dev dependencies out into a shell.nix file does not help.

You can see and run it yourself from philschonholzer/haskell-example-project (github.com)

How can I get nix-build to run reliably and have the dev dependencies available at the same time?

Try NIX_SHELL= nix-build.

Thanks, but sadly it still does not work.

Just to check, you did notice the space, right?

Yes, I guess the idea is to set the env to empty. But it sadly didn’t help.

I might be wrong with the name of the envvar. Check what’s set in your shell, I shouldn’t be too far off… maybe it’s IN_NIX_SHELL :thinking:

1 Like

YES! This works! Thank you! Actually I guess I should be able to set IN_NIX_SHELL to empty in the default.nix. Thank you very much! :relaxed:

1 Like

Ok it works, but is it a good idea?

I like to think why this feature exists in the first place.

Something doesn’t feel right about this.

So far I haven’t run into any problems with it, but then I only use it very sparingly. I might for instance put something like IN_NIX_SHELL= nix-build into a Makefile to easily test, during development, that a full build still works. Just to not have to deny/allow direnv manually.

I suspect it’s there for a reason though, so wouldn’t unset the variable all the time.

1 Like