In what order are overlays applied when defining nixpkgs.overlays in multiple modules?

Given

# ModuleA.nix

{ ... }:

{
  nixpkgs.overlays = [ (self: super: { self.my.example = "hello"; }) ];
}

and

# ModuleB.nix

{ ... }:

{
  nixpkgs.overlays = [ (self: super: { self.my.example = "goodbye"; }) ];
}

assuming both are imported into a nixos config, is there a rule that tells you what pkgs.my.example resolves to? What information if any am I missing to determine the order overlays are applied?

I’m aware that in context of import <nixpkgs> { overlays = [ moduleAOverlay moduleBOverlay]; } that the moduleBOverlay wins out. I’m looking for a similar rule I can apply to nixpkgs.overlays.

You can control the order they are merged in by setting the priorities with mkOrder/mkBefore/mkAfter.

If you want some overlay applied first, you can do something like:

{
  nixpkgs.overlays = lib.mkBefore [(final: prev: { example = "hello"; })];
}
2 Likes

I see. Thanks!

Is there any order among overlays with the same priority? Or is that left undefined?

Yeah, I don’t think it would be a good idea to rely on order with the same priority. As far as I know, its not documented.

1 Like