My Overlay Is Not Recognized as A Function

Hi,

I’m packaging a proprietary C/C++ library into a flake and would like to provide an overlay for downstream projects. At first, I have a default.nix that provides the derivation:

{ pkgs ? import <nixpkgs> {
  config = { allowUnfree = true; };
}}:
pkgs.stdenv.mkDerivation rec {
  ...
}

And the flake for this library (both nix build and nix develop can work as expected):

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
        };
      in
      {
        packages.default = pkgs.callPackage ./default.nix { inherit pkgs; };

        overlay = final: prev: { 
          fpgamgr = pkgs.callPackage ./default.nix { 
            pkgs = final;
          };
        };

        devShells.default = pkgs.callPackage ({ mkShell, pkg-config, ... }:
          mkShell {
            buildInputs = with pkgs; [
              cmake
              coreutils
            ];
          }
        ) {};
      }
    );
}

The problem is on the overlay when I create another flake for my application:

{
  description = "Demo Application";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";

    # The folder contains both default.nix and flake.nix mentioned above
    fpgamgr.url = "./../nixos";
  };

  outputs = { self, nixpkgs, flake-utils, fpgamgr }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          overlays = [ fpgamgr.overlay ];
        };
      in
      {
        devShells.default = pkgs.callPackage ({ mkShell, pkg-config, ... }:
          mkShell {
            buildInputs = with pkgs; [
              fpgamgr
              cmake
              coreutils
            ];
          }
        ) {};
      }
    );
}

When I call nix develop against this flake, it throws this error: All overlays passed to nixpkgs must be functions. This confuses me a lot because it looks like a function to me. Does it somehow get evaluated?

Many thanks.

This is the same issue as How to consume a `eachDefaultSystem` flake overlay?flake-utils.lib.eachDefaultSystem will create a per-system variant of each attribute, so your overlay is actually under fpgamgr.overlay.x86_64-linux. You should see that when you run nix flake show in the library flake directory.

Overlays should generally be system-independent and should refer only to final/prev attributes and other system-independent files (e.g. local Nix files and external sources). Notably, you should not refer to specific instance of Nixpkgs.

The solution is to move the overlay and other system-independent attributes outside of the eachDefaultSystem call. And replace pkgs.callPackage with prev.callPackage. Or just import, since you are not really using the automatic passing of arguments from scope.

1 Like

Thank you so much. I didn’t realize it has something to do with flake-utils.

I’m now hitting another wall related to the default.nix where mkDerivation is not storing my src, but I think that belongs to a different topic.