Extending linuxPackages_4_19 in overlay doesn't seem to work

I’m trying to add a package to linuxPackages_4_19 using overlays in NixOS 19.09.

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

My /etc/nixos/overlays contains one file, parallels.nix, which looks like this:

self: super:
{
  linuxPackages_4_19 = super.linuxPackages_4_19.extend (linuxPackagesSelf: linuxPackagesSuper: {
    prl-tools = ((super.callPackage <nixpkgs/os-specific/linux/prl-tools> { }).overrideAttrs (oldAttrs: rec {
      prl_major = "15";
      version = "${oldAttrs.prl_major}.1.2-47123";
      ...
    }));
  });
}

However, Nix seems to ignore my overlay:

[ersin@workspace:~]$ sudo nix-env -i linuxPackages_4_19.prl-tools
error: selector 'linuxPackages_4_19.prl-tools' matches no derivations

Any ideas why this is happening?

but you put your file into

?

Sorry, typo. My overlays are in /etc/nixos/overlays. I edited the original post to reflect this fact.

as sudo changes the user, it might be referencing different settings.

For example:

$ nix-channel --list
home-manager https://github.com/rycee/home-manager/archive/master.tar.gz
nixpkgs https://nixos.org/channels/nixos-unstable
[11:19:14] jon@jon-workstation ~/projects/nixpkgs (staging-next)
$ sudo !!
sudo nix-channel --list
[sudo] password for jon:
nixos https://nixos.org/channels/nixos-unstable

also, nix-env has some odd behavior, and might not even be referencing your overlays, as I think it only references channels? (not actually sure, never use nix-env)

@jonringer, the sudo doesn’t matter in my case. I get the same results when logged in as root, as well.

If nix-env is unreliable (which btw is really frustrating–the docs simply state that setting up overlays the way that I’ve done will make overlays available to “all Nix tools”), what method do you recommend for me to do a one-off installation of an overlayed package?

what @jonringer says is that sudo can change NIX_PATH. I have custom NIX_PATH set, but it is still different in sudo:

$ env | grep NIX_PATH
NIX_PATH=/home/danbst/.nix-defexpr/channels:/home/danbst/power-profile/sources

$ sudo env | grep NIX_PATH
NIX_PATH=/home/danbst/power-profile/sources

This can be mitigated with sudo -E.

Btw, I’ve checked your overlay, it works fine, but just like you, when running sudo nix-env I get an error, which indicates overlay is not used.

1 Like

sudo executes a command as root, so this makes sense. I was commenting on the difference between nix-env and sudo nix-env.

If nix-env is unreliable (which btw is really frustrating–the docs simply state that setting up overlays the way that I’ve done will make overlays available to “all Nix tools”), what method do you recommend for me to do a one-off installation of an overlayed package?

nix-env is differrent in a lot of regards (to emulate behavior of other package ecosystems, see my previous link). I think the “nix tools” is referring to the other tooling such as nix-build, and the 2.0 nix XXX commands.

nix-env should respect overlays. My first suggestion is to compare the output of nix eval '(<nixpkgs-overlays>)' and sudo nix eval '(<nixpkgs-overlays>)' to make sure both spit out the same path. sudo shouldn’t be changing the NIX_PATH var but this is just a sanity check.

Alright, so…based on the post that you quoted, @jonringer, and looking up the man page for nix-env, I was able to figure out that the -i option when used by itself seems to be using some sort of heuristic to find the correct derivation based on the name provided, whereas I was trying to pass a specific attribute path.

A more precise command is:

nix-env -f '<nixpkgs>' -iA linuxPackages_4_19.prl-tools

which gives me the following error:

error: assertion failed at /nix/var/nix/profiles/per-user/root/channels/nixos/pkgs/os-specific/linux/prl-tools/default.nix:9:1

which is due to the following line in prl-tools/default.nix:

assert kernel != null -> stdenv.lib.versionOlder kernel.version "4.15";

In other words, I believe that nix-env is now seeing the overlays when I use the -A option. I’ve fixed my problem, although I’m not precisely sure why it was happening.

1 Like

nix-env will search a lot of places for a package, for example:

$ nix-env -qaP cmake
nixos.cmake_2_8    cmake-2.8.12.2
nixpkgs.cmake_2_8  cmake-2.8.12.2
nixos.cmake        cmake-3.15.4
nixpkgs.cmake      cmake-3.15.4

it possible that it was trying to install nixos.linuxPackages_4_19.prl-tools