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

nix-direnv cannot find nixpkgs with nix-2.4 #119

Closed
deejayem opened this issue Nov 3, 2021 · 4 comments
Closed

nix-direnv cannot find nixpkgs with nix-2.4 #119

deejayem opened this issue Nov 3, 2021 · 4 comments

Comments

@deejayem
Copy link

deejayem commented Nov 3, 2021

I have a .envrc containing use nix, and a shell.nix containing with import <nixpkgs> {}; stdenv.mkDerivation { name = "name"; nativeBuildInputs = [ (leiningen.override { jdk = jdk11; }) ]; }

This works fine with nix 2.3, but after upgrading to nix (Nix) 2.4pre-rc1, I get the following when I cd into the directory:
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

However, nix-shell still works, and if I use direnv without nix-direnv, that also works.

I'm on macos, and am using home-manager (programs.direnv.nix-direnv.enable = true;), if that's relevant.

$ nix-channel --list`
home-manager https://github.com/nix-community/home-manager/archive/master.tar.gz
nixpkgs https://nixos.org/channels/nixpkgs-unstable

The full output after using cd is as follows:

direnv: loading ~/src/foo/.envrc
direnv: using nix
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)
direnv: using cached derivation
direnv: eval /Users/djm/src/foo.direnv/cache-unknown
direnv: export +IN_NIX_SHELL +TEMPDIR +XDG_DATA_DIRS ~PATH
@Mic92
Copy link
Member

Mic92 commented Nov 3, 2021

It seems that NIX_PATH is no longer set by your setup. In NixOS where I use flakes I usually solve it like this: https://github.com/Mic92/dotfiles/blob/f4711c4cd4fb717130da4e3e1a8ba6263fa20507/nixos/configurations.nix#L21

If you use channels make sure that they are included in your $NIX_PATH environment variable:

$ ls -la $HOME/.nix-defexpr/channels
nixpkgs 
$ export NIX_PATH=$HOME/.nix-defexpr/channels

Sorry but this issue is not related to nix-direnv and nix-direnv cannot magically fix your setup. So I am closing this.
I hope the instructions above are helpful.

@Mic92 Mic92 closed this as completed Nov 3, 2021
@mkhl
Copy link
Contributor

mkhl commented Nov 11, 2021

it seems that nix 2.4 is using default values when NIX_PATH is unset (NixOS/nix@ec9dd9a), and that because of this the default profile setup doesn't set NIX_PATH anymore

so the cause of this issue is that nix-direnv depends on and uses nix-2.3.16 instead of the nix it's installed with, and that version fails to deal with the setup provided by nix 2.4 (and generates warnings about newer config settings like warning: unknown setting 'experimental-features')

@Mic92
Copy link
Member

Mic92 commented Nov 12, 2021

it seems that nix 2.4 is using default values when NIX_PATH is unset (NixOS/nix@ec9dd9a), and that because of this the default profile setup doesn't set NIX_PATH anymore

so the cause of this issue is that nix-direnv depends on and uses nix-2.3.16 instead of the nix it's installed with, and that version fails to deal with the setup provided by nix 2.4 (and generates warnings about newer config settings like warning: unknown setting 'experimental-features')

We upgraded nix-direnv to point to nix-2.4 now by default quite recently: NixOS/nixpkgs#145236

@mkhl
Copy link
Contributor

mkhl commented Nov 12, 2021

perfect, then i'll just wait until that gets released and hits the channel. thank you!

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

No branches or pull requests

3 participants