Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading dependencies from nixpkgs-unstable with nix-shell

Tags:

nix

nixos

I am on NixOS 16.09 and I want to use packages which are currently only in nixpkgs-unstable / nixos-unstable.

Using nix-channel --add, I was able to add nixpkgs-unstable to my (user) channels and use it to install the latest version of some packages with nix-env.

However, I understand that while nix-env depends on user-defined channels, nix-shell instead depends on the NIX_PATH environment variable, in my case:

$ echo $NIX_PATH 
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

So this clearly shows the problem: nix-shell is going to use the system-wide NixOS 16.09 channel instead of the user-defined nixpkgs-unstable channel.

Right now, I am using this workaround:

nix-shell -I nixpkgs=~/.nix-defexpr/channels/nixpkgs

It does not look very pretty to me. What would be the recommended way of doing this?

Is it to add something like:

export NIX_PATH="nixpkgs=~/.nix-defexpr/channels/nixpkgs:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels"

to my .profile? It does not look very pretty either.

like image 908
Zimm i48 Avatar asked Nov 10 '16 16:11

Zimm i48


2 Answers

Welcome to a long-standing confusion with nix-env and NIX_PATH. It is explicitly stated, that nix-env doesn't use NIX_PATH, which makes it (I think) the only Nix tool which doesn't respect NIX_PATH.

So, the actual problem is with nix-env here, not nix-shell. I'll post a bunch of issues on Nix bug tracker about this:

  • https://github.com/NixOS/nix/issues/993
  • https://github.com/NixOS/nix/issues/1067
  • https://github.com/NixOS/nix/issues/886

Right now, I using this workaround:

So now you can see, this isn't a workaround. It is a good practice to always specify which exact Nixpkgs you'd like to use: your roots channel version, your channel version, upstream remote channel version, local git checkout or pinned git version.

like image 135
danbst Avatar answered Oct 07 '22 23:10

danbst


To complete the other answer, here is a good reference that I just found that explains NIX_PATH and the fact that nix-env does not use it: http://lethalman.blogspot.fr/2014/09/nix-pill-15-nix-search-paths.html

like image 36
Zimm i48 Avatar answered Oct 07 '22 22:10

Zimm i48