Patching Firefox with an overlay not working

Hi, I am trying to patch Firefox with "LegacyFox”, a shim that essentially jury-rigs Firefox into running legacy extensions, in particular VimFx.

I created an overlay to build a new firefox-legacy package and I made Firefox use this package with home manager. But It doesn’t work

overlays/firefox.nix:

inputs:

final: prev: {
  firefox-legacy = prev.firefox.overrideAttrs (old: {
    postInstall =
      (old.postInstall or "")
      + ''
        cp ${inputs.legacyfox}/config.js \
          $out/lib/firefox/

        cp ${inputs.legacyfox}/legacy.manifest \
          $out/lib/firefox/

        rm -f $out/lib/firefox/defaults/pref/channel-prefs.js
        rm -f $out/lib/firefox/defaults/pref/autoconfig.js

        cp ${inputs.legacyfox}/defaults/pref/config-prefs.js \
          $out/lib/firefox/defaults/pref/autoconfig.js

        cp -r ${inputs.legacyfox}/legacy \
          $out/lib/firefox/
      '';
  });
}

flake.nix:

{
  description = "My NixOS system";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    legacyfox = {
      url = "git+https://git.gir.st/LegacyFox.git";
      flake = false;
    };
  };

  outputs = { self, nixpkgs, home-manager, legacyfox, ... }@inputs:
    let
      system = "x86_64-linux";
    in
    {
      nixosConfigurations.sigismund = nixpkgs.lib.nixosSystem {
        inherit system;

        specialArgs = {inherit inputs;};
	
        modules = [
          {
            nixpkgs.overlays = [
              (import ./overlays/firefox-legacy.nix inputs)
            ];
          }
          ./configuration.nix

          home-manager.nixosModules.home-manager
	  {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.extraSpecialArgs = { inherit inputs; };
            home-manager.users.max = import ./home.nix;
          }
        ];
      };
    };
}

However, this doesn’t appear to work. When I inspect firefox’s runtime environment by running whereis firefox I don’t see the files I copied in using the overlay.

Could someone help me out and maybe point out where I am going wrong because I’d really like to get this patch working and start enjoying this operating system.

The firefox-legacy defined in overlay seems not used at all, you should use home-manager’s option programs.firefox.package in your home.nix instead, something like:

{
  inputs,
  config,
  lib,
  pkgs,
  ...
}:

{
  programs.firefox.package =
    (pkgs.firefox.override (old: {
      extraPrefsFiles = (old.extraPrefsFiles or [ ]) ++ [ (inputs.legacyfox + "/config.js") ];
    })).overrideAttrs
      (old: {
        buildCommand = (old.buildCommand or "") + ''
          ln -s ${inputs.legacyfox}/legacy $libDir/
          ln -s ${inputs.legacyfox}/legacy.manifest $libDir/
        '';
      });
}

My firefox and vimfx setup if you interested.

Thank you. I didn’t expect to find someone else who uses this exact extension.

However even after a lot of fiddling I haven’t been able to get LegacyFox to work with Home-Manager. The key problem seems to be that LegacyFox relies on setting preferences to override AutoConfig, but firefox is applying those preferences too late with extraPrefsFiles or the other ways to set preferences in home-manager. Your module uses programs.firefox.autoconfig, but Home-Manager lacks an equivalent.

Update: AHA! I found a workaround to get LegacyFox working while still using Home-Manager. Since programs.firefox.autoconfig just replaces mozilla.cfg (which is just a bunch of javascript), I just replaced it manually with the config.js file shipped with LegacyFox. No need to set any preferences to get Firefox to do this for us.

  programs.firefox.package =
    pkgs.firefox.overrideAttrs
      (old: {
        buildCommand = (old.buildCommand or "") + ''
          ln -s ${inputs.legacyfox}/legacy $libDir/
          ln -s ${inputs.legacyfox}/legacy.manifest $libDir/
          ln -sf ${inputs.legacyfox}/config.js $libDir/mozilla.cfg
        '';
      });

and on the vimFX side:

        "VimFx-unlisted@akhodakivskiy.github.com" = {
          install_url       = "https://github.com/akhodakivskiy/VimFx/releases/download/v0.27.5/VimFx.xpi";
          installation_mode = "force_installed";
          updates_disabled  = true;
        };