How to configure multiple packages using single home-manager module?

I’m using Firefox home-manager module to configure Librewolf package like this:

    programs = {
      firefox = {
        enable = true;
        package = pkgs.librewolf;
        # rest of config

but I also want to configure actual Firefox package in the same way, but since home-manager doesn’t allow multiple programs.firefox definitions I’m getting this error:

       error: The option `home-manager.users.<user>.programs.firefox.package' is defined multiple times while it's expected to be unique.

I was thinking if it would be possible to write an overlay that would create Librewolf home-manager module which inherits Firefox module and overwrites attributes needed to make it work with Librewolf? But I was unable to find any information on how to do that, if it’s even possible? Maybe there is other ways to achieve this?

Why don’t you use the programs.librewolf.* options if you want both browsers?

It seems that librewolf home-manager module doesn’t offer same customization options that firefox does.
It only offers programs.librewolf.settings which has different capabilities compared to programs.firefox.policies that allow much more configuration, including declarative extension management…

Then copy the ff module into a file, make necessary changes to make it work with lw, and add the file to imports

Then you’d be able to use programs.librewolf.policies with this new module

Thanks for the suggestion, I made it work, but it’s not ideal…

  1. If it would be possible to create an overlay that inherits existing module and overrides only what’s needed, I likely wouldn’t need to do any maintenance for it while still being able to get updates in the future from underlying firefox module, as long as things that I override don’t get refactored in firefox module…
  2. I had to change some things that I don’t really understand because they had to be unique for both firefox and my forked librewolf-firefox modules. And now I’m also afraid that some configs or other files may be shared between these two modules while they shouldn’t be. Anyway, I would likely also be having these issues if I were able to extend firefox module with overlay, so I guess both approaches are not very viable unless you really know what you are doing…

Overlays apply to packages in a nixpkgs instance, not HM or NixOS modules.