mozilla / nixpkgs-mozilla

Mozilla overlay for Nixpkgs.
MIT License
516 stars 128 forks source link

Install different versions of Firefox side by side. #296

Closed zeorin closed 6 months ago

zeorin commented 2 years ago

It'd be great to have first-class support in the overlay for installing different versions of Firefox side by side, at the moment this is not possible.

I have the following workaround:

let
  mkFirefox = { name, desktopName, profileName }:
    let
      pkg = latest."${name}-bin".overrideAttrs (old: {
        desktopItem = makeDesktopItem {
          inherit name desktopName;
          exec = "${name} %U";
          icon = name;
          comment = "";
          genericName = "Web Browser";
          categories = [ "Network" "WebBrowser" ];
          mimeTypes = [
            "text/html"
            "text/xml"
            "application/xhtml+xml"
            "application/vnd.mozilla.xul+xml"
            "x-scheme-handler/http"
            "x-scheme-handler/https"
            "x-scheme-handler/ftp"
          ];
        };
      });
      wrapped = pkgs.writeShellScriptBin name ''
        exec ${pkg}/bin/firefox --no-remote -P ${profileName} "''${@}"
      '';
    in pkgs.symlinkJoin {
      inherit name;
      paths = [ wrapped pkg ];
    };
in [
  latest.firefox-bin
  (mkFirefox {
    name = "firefox-nightly";
    desktopName = "Firefox Nightly";
    profileName = "nightly";
  })
  (mkFirefox {
    name = "firefox-beta";
    desktopName = "Firefox Beta";
    profileName = "beta";
  })
  (mkFirefox {
    name = "firefox-esr";
    desktopName = "Firefox ESR";
    profileName = "esr";
  })
]

This changes the binary name (so there's no clash and all can be installed side by side), and overwrites the desktop item definition so that we can actually tell the different versions apart using your Desktop Environment's application launcher.

nbp commented 2 years ago

@zeorin I recall we had a live discussion about this topic on Matrix. Last time we spoke about changing the way the Firefox wrapper is handled in Nixpkgs, as this overlay relies on Nixpkgs wrapper to provide binaries.

I suspect we can close this issue and reference another one in Nixpkgs?

zeorin commented 6 months ago

https://github.com/NixOS/nixpkgs/pull/294971