Overriding package in overlay using `prev.pkgs{Static,Musl}.<package>` evaluates derivation attributes twice

We have a flake setup within which we override some packages with overlays, e.g. universal-ctags, to statically build them for darwin+linux, or otherwise modify them. Link to the flake where we apply the set of overlays and then create devShells, expose packages as outputs etc.

For universal-ctags, we also create a symlink from $out/bin/universal-ctags to $out/bin/ctags using postFixup in overrideAttrs. This would error out however, stating that the file already existed. Upon looking further (adding ls -l $out/bin to postFixup), I noticed that it was invoking the contents of my postFixup twice. Sprinkling some builtins.trace, I could see that the attributes to overrideAttrs were being evaluated twice. The following builtins.trace was giving the following output (first call prints the rhs of the oldAttrs.postFixup or "nada" expr):

trace: nada
trace: # unideal -f here, theres a weird double-eval going on here
ln -sf $out/bin/ctags $out/bin/universal-ctags

You can reproduce the issue by running nix build 'github:Sourcegraph/sourcegraph/8c7718c1cc91150cb6772dc70ae8f0f8ded8356a#universal-ctags' yourself.

Exploring further, this doesn’t happen when we make any of the following changes:

  • Use prev.universal-ctags.override{Attrs} instead of prev.pkgs{Static,Musl}.override{Attrs}.
    • This is not a solution for us, as we specifically want to statically build them.
  • Don’t shadow universal-ctags in the overlay aka assign the overridden universal-ctags to a new name like universal-ctags' = prev.pkgsStatic.universal-ctags.override{Attrs}
    • Possible solution but I feel this shouldn’t be necessary

Same issue happens in our overriding of comby in comby.nix, where we’re using prev.pkgsMusl.comby with a postPatch override. Overriding prev.comby as opposed to prev.pkgsMusl.comby also removes the double evaluation, but again not desirable for us as we want a musl-based comby.

Not sure if Im missing something in this post to help give context, so please do ask any questions I can help clarify. All links should be pinned to a specific commit so they won’t change. Thanks everyone : )