Nixos-rebuild doesn't pick up overlay files from NIX_PATH

I’m having difficulties getting overlays that are working with user’s nix-env to also apply to the system-wide nixos-rebuild. Having studied Overlays - NixOS Wiki I’m not getting any wiser - from my understanding of that, this should work.

Any clever heads in here that can spot (or suggest debugging steps to understanding) why [root@USERNAME-desktop:~]# NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays" nixos-rebuild switch doesn’t pick up the overlays I have in /etc/nixos/overlays/*.nix?

Details:

I’m on 20.03, having environment.systemPackages = with pkgs; [... nextcloud-client ... ] in my configuration.nix so I get nextcloud-client version 2.6.4:

[root@USERNAME-desktop:~]# nix-channel --update 
unpacking channels...
created 1 symlinks in user environment

[root@USERNAME-desktop:~]# nix-channel --list
nixos https://nixos.org/channels/nixos-20.03

[root@USERNAME-desktop:~]# nix-env -e nextcloud-client

[root@USERNAME-desktop:~]# nixos-rebuild switch
building Nix...
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for USERNAME...
setting up tmpfiles

[root@USERNAME-desktop:~]# nextcloud --version
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
Nextcloud version 2.6.4git
Git revision b45f5fd1a947dc21eb11c69049a99616a2ec950e
Using Qt 5.12.7, built against Qt 5.12.7
Using 'OpenSSL 1.1.1g  21 Apr 2020'

I have an overlay in /etc/nixos/overlays/nextcloud-client.nix to get version 3.0.3:

root@USERNAME-desktop:~]# cat /etc/nixos/overlays/nextcloud-client.nix 
self: super: {
  nextcloud-client = super.nextcloud-client.overrideAttrs (old: rec{
    version = "3.0.3";

    src = super.fetchFromGitHub {
      owner = "nextcloud";
      repo = "desktop";
      rev = "v3.0.3";
      sha256 = "0idh8i71jivdjjs2y62l22yl3qxwgcr0hf53dad587bzgkkkr223";
    };

    buildInputs = old.buildInputs ++ [
      super.qt5.qtquickcontrols2
      super.qt5.qtgraphicaleffects
    ];
  });
}

I would expect this nixos-rebuild switch to pick up the overlay, but it doesn’t:

[root@USERNAME-desktop:~]# NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays" nixos-rebuild switch
building Nix...
building the system configuration...
activating the configuration...
setting up /etc...
reloading user units for USERNAME...
setting up tmpfiles

[root@USERNAME-desktop:~]# nextcloud --version
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
Nextcloud version 2.6.4git
Git revision b45f5fd1a947dc21eb11c69049a99616a2ec950e
Using Qt 5.12.7, built against Qt 5.12.7
Using 'OpenSSL 1.1.1g  21 Apr 2020'

While nix-env does:

[root@USERNAME-desktop:~]# NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays" nix-env -i nextcloud-client
installing 'nextcloud-client-3.0.3'
building '/nix/store/il2f3z8jd5hq8mcjp4nk6vhgagww6k8i-user-environment.drv'...
created 17 symlinks in user environment

[root@USERNAME-desktop:~]# nextcloud --version
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
Nextcloud version 3.0.3git
Git revision 78da725ac38e1508e5800d02fd1700a4e43b1088
Using Qt 5.12.7, built against Qt 5.12.7
Using Qt platform plugin 'xcb'
Using 'OpenSSL 1.1.1g  21 Apr 2020'
Running on NixOS 20.03 (Markhor), x86_64

And the bit of the wiki from which I understand that both of the above should bring in the overlay:

On the system level

If you want your overlays to be accessible by nix tools and also in the system-wide configuration, add nixpkgs-overlays to your NIX_PATH:

NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays"

Currently nixos-rebuild only works with a path that is a directory.

Finally, the whole lot of the code lives here: https://gitlab.com/kidmose/dotfiles/-/tree/master/nixos

Try using nixpkgs.overlays in /etc/nixos/configuration.nix. For example, I have overlays in my NUR repo and I use them like this:

  nixpkgs.overlays = [   
    nur-without-pkgs.repos.emmanuelrosa.overlays.pendingPR
    nur-without-pkgs.repos.emmanuelrosa.overlays.fonts
  ];

Perhaps for you it would be something like:

  nixpkgs.overlays = [
      /etc/nixos/overlays/nextcloud-client.nix
  ];

The exact snippet produces an error:

The option value `nixpkgs.overlays.[definition 2-entry 1]' in `/etc/nixos/configuration.nix' is not of type `nixpkgs overlay'.

Adding this applies my overlay:

nixpkgs.overlays = [
  (import /etc/nixos/overlays/nextcloud-client.nix)
];

I was hoping to apply all the overlays in the folder, and not having to maintain the the path of each in configuration.nix. Sorry if that was unclear and thanks for the suggestion!

You can apply all of the overlays in a folder if you have a default.nix in the folder with each overlay defined.

/etc/nixos/overlays/default.nix

{
  nextcloud-client = import ./nextcloud-client.nix;
  # additional overlays here.
}

/etc/nixos/configuration.nix

...

nixpkgs.overlays = [
  (import /etc/nixos/overlays)
];
1 Like