Why is my flake overlay failing?

Hello all,

I have a fairly simple situation where I’m defining an overlay in one flake and using it in another.

In the dependency flake I’ve defined a package called zlib - nb, there is already a package with the same name in nixpkgs, and put it into that flake’s overlay:

        zlib = with pkgs; callPackage ./zlib.nix {};
      in {
        packages.default = zlib;
        overlays = final: prev: { inherit zlib; };

That all builds fine and no errors there. nix eval --raw .# gives me the store path for this, /nix/store/vn36lf7ilbcnwl2bd0qpsixi7gfxkvmi-zlib. So far so good.

I then have a second flake, which imports the dependency flake, and uses its overlay to define pkgs:

  inputs = {
    nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
    flake-utils.url = "github:numtide/flake-utils";
    zlib.url = <path to zlib flake here>;
          pkgs = import nixpkgs {
            inherit system;
            overlays = [ zlib.overlays.${system} ];
          packages = {
            mainPackage = with pkgs; callPackage ./main_package.nix { };

where the derivation in main_package.nix lists zlib as one of its parameters.
Unfortunately it’s taking the pre-existing nixpkgs zlib instead of my new one, as I can see by looking at the store paths in nix show-derivation .#mainPackage. Am I making some elementary mistake here? I can’t see how.


Overlays are not system-spaced, so I’m not sure what you’re doing zlib.overlays.${system} for, nor why it’s not yelling at you when you try.

Also, when defining the overlay, you should probably be using zlib = final.callPackage ./zlib.nix {};, rather than pulling in a separate nixpkgs invocation just for zlib.

However, for the main question, of why it’s not picking up the new package, the only thing I can think of is that you defined callPackage with a let or an argument binding somehow, and it’s overriding the with pkgs;.

OK, thank you, I’m at least reassured by the fact that I’ve not misunderstood the expected behaviour.

Are you sure overlays are not system-spaced? If I do nix flake show it will show me:

< flake base >
│   ├───aarch64-darwin: Nixpkgs overlay
│   ├───aarch64-linux: Nixpkgs overlay
│   ├───x86_64-darwin: Nixpkgs overlay
│   └───x86_64-linux: Nixpkgs overlay

Overlays are named. Somehow you’re getting system strings as the names.

I’m using flake-utils.lib.eachDefaultSystem from "github:numtide/flake-utils";, that’s probably the reason.

Yeah, a quick check of the code says flake-utils.lib.eachDefaultSystem doesn’t know about overlays not being system-spaced. I think you might be expected to know that yourself and put them in with // outside of the call.

Is there any way you know of to examine the contents of an overlay? They don’t get expanded out in eg nix flake show.

Load it up in the repl, and examine overlay pkgs pkgs (technically wrong, but wouldn’t matter for this case).

OK, thanks, I’ll figure it out from there.