Do I need a scope to have multiple derivations in one `package.nix`?

I have a package.nix that looks something like:

{lib, stdenv, makeWrapper}:
let
  baseName = "my-package";
  version = "0.0.0";
  src = ./.;
in {
  "${baseName}" = stdenv.mkDerivation {
    pname = baseName;
    inherit version src;
    # do stuff ...
  };

  "${baseName}-auxiliary" = stdenv.mkDerivation {
    pname = "${baseName}-auxiliary";
    inherit version src;
    # do stuff ...
  };
}

Since both of these packages are small and trivial, I thought it would be nice for them to share a lot of the configuration in the let block.

I tried to use it in a NixOS module as:

defaultPackage = (pkgs.callPackage ./package.nix {}).my-package-auxiliary;

Both derivations are provided as default packages in modules, which are very similar. One is for NixOS, and the other is for Home Manager.

When I try to .override one of the packages I am told there is no such attribute override. Do I need to put these in a package scope to make callPackage work? I thought I could just make the package an attribute set without passing it through mkDerivation, and that callPackage would figure it out, evidently this is not the case.

.override is the result of callPackage. It is given to whatever is returned to callPackage. If that “whatever” is an attribute set of packages, then the .override that it adds is on the attribute set, not the elements therein.

You can use callPackages here, which makes each child overrideable.

1 Like

Thank you! Didn’t notice the plural version of the function.

1 Like