1

I'm trying to install this Python library python3.6-geopandas-0.3.0. And I successfully installed it imperatively with

$ nix-env -iA nixpkgs.python3Packages.geopandas

However I need to create an expression so that my Python environment includes it.

with import <nixpkgs> {};

python36.withPackages (ps: with ps; [
  geopandas
])

Turns out I get

installing ‘python3-3.6.4-env’
error: undefined variable ‘geopandas’

I have both nixos and nixpkgs-unstable configured in my system. Not sure if correctly though. I have channel nixos for root and nixpkgs for my user.

$ 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

I would like to make nixpkgs-unstable the default channel for my user, or at least make its packages visible as an overlay, so I could run the above expression successfully.

dmvianna
  • 397
  • 3
  • 14

2 Answers2

2

Your expression works for me on current nixpkgs master. I would investigate if your NIX_PATH isn't taking some old <nixpkgs> that you didn't expect, e.g. geopandas isn't present on the 17.09 stable branch.

Vladimír Čunát
  • 1,258
  • 7
  • 11
  • `$ 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` – dmvianna Feb 16 '18 at 11:08
  • I would like to use stable in root and unstable in the user environment. Is that possible? – dmvianna Feb 18 '18 at 09:32
2

I was able to reproduce this on NixOS.

Your NIX_PATH sets nixpkgs to /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs which if you look up is just a symlink to /nix/var/nix/profiles/per-user/root/channels/nixos/. It's probably a little hack to make work all the expressions that are in the wild that expect <nixpkgs> to point to a valid channel path (even though I don't think it's a requirement for a nix system and seems to originate from nix-daemon).

To fix it you either have to redefine NIX_PATH to point to an actual nixpkgs channel or you have to explicitly state the path to the channel instead of using <nixpkgs> in your expression.

You can find your available channels in ~/.nix-defexpr:

$tree -l -L 2 ~/.nix-defexpr/
/home/user1/.nix-defexpr/
├── channels -> /nix/var/nix/profiles/per-user/user1/channels
│   ├── ...
│   └── nixpkgs -> /nix/store/qz1.../nixpkgs
└── channels_root -> /nix/var/nix/profiles/per-user/root/channels
    ├── ...
    └── nixos -> /nix/store/53b.../nixos

(channels contains the user-specific channels while channels_root contains the channels that root subscribed to and are available to all users)

So if you decided to use the user1's subscription to nixpkgs then you would run:

NIX_PATH="nixpkgs=/home/user1/.nix-defexpr/channels/nixpkgs" nix-env -f default.nix -i

Thomas
  • 6,242
  • 8
  • 26
  • 32
fghibellini
  • 121
  • 3
  • I understood everything until the last line. However what I need to do is to set `nixpkgs-unstable` as the default channel for my user. I will not be using a `default.nix` file. How would I correct the behaviour then? – dmvianna Feb 17 '18 at 20:32
  • the last line was just an example command. just prefix the command that threw your error with `NIX_PATH="nixpkgs=/home/user1/.nix-defexpr/channels/nixpkgs"`. I don't think there's such a thing as a "default channel". – fghibellini Feb 17 '18 at 20:35
  • 1
    `` is not some magic bound to a "default channel" - it just instructs nix to look into the NIX_PATH linux environment variable and look for an assignment of the form "nixpkgs=..." and use the right side of the assignment as the value of ``. You can prefix any command in linux with an assignment like I showed above and it will set the environment variable just for that one command invocation. – fghibellini Feb 17 '18 at 20:39
  • The only thing close to having a channel as default is setting NIX_PATH to that value in your system config or in your rc files - I don't know what's the best practice regarding that. – fghibellini Feb 17 '18 at 20:44
  • 1
    see https://stackoverflow.com/questions/36452057/nixos-setting-the-default-channel-in-configuration-nix – fghibellini Feb 17 '18 at 20:46
  • I was under the impression I could have `unstable` for the user and `stable` for root. This clearly works well when I do things imperatively, but I'm not sure how to do it declaratively. – dmvianna Feb 17 '18 at 21:55
  • Oh. `$ cat ~/.nix-defexpr/channels/manifest.nix` gives me `[ ]`. Nothing else in that directory. That's unexpected. `~/.nix-defexpr/channels_root` is chock full of stuff though. – dmvianna Feb 18 '18 at 09:27
  • your intuition that the channel subscriptions work well only with the imperative interface is correct. The nix config file should contain ale the configuration of a system, thus allowing you to replicate the system on another machine by just copying this one file and running `nix-rebuild switch`. If the declarative interface was dependant on the channel subscriptions you would always have to setup these first and only then you could apply the new config file. – fghibellini Feb 23 '18 at 21:20
  • 1
    I believe the config gets passed the package set of the 'nixos' channel root is subscribed to, but I cannot find any documentation regarding it. – fghibellini Feb 23 '18 at 21:22
  • the fact that your ~/.nix-defexpr/channels folder contains only manifest.nix is indeed weird. – fghibellini Feb 23 '18 at 21:26
  • exactly. I want to be able to reproduce the user environment in multiple machines as well. I don’t want to give root access to stuff that should run as an user. – dmvianna Feb 23 '18 at 21:33
  • then you shouldn't really care about the subscriptions other than root's subscription called 'nixos' (see [nixos-rebuild updates subscription to nixos](https://github.com/NixOS/nixos/blob/5f444a4d8d49a497bcfabe2544bda264c845653e/modules/installer/tools/nixos-rebuild.sh#L140)) – fghibellini Feb 23 '18 at 21:51
  • if you want to use packages that are not in the nixos channel but in nixpkgs for example, then you should reference the channel by url as showed in the above referenced issue. – fghibellini Feb 23 '18 at 21:53
  • I believe I've seen come config file that fetched the channel by url, assigned it to a variable and then all the packages from that channel were available in the config as attributes of that variable. But I can't find an example rn. – fghibellini Feb 23 '18 at 21:59
  • see the documentation for 'fetchTarball url' in https://nixos.org/nix/manual/ – fghibellini Feb 23 '18 at 22:04
  • 1
    another example of using fixed channels with a good explanation https://garbas.si/2015/reproducible-development-environments.html – fghibellini Feb 25 '18 at 13:57