I would like to manage Firefox extensions in the same way as configuration option programs.chromium.extensions for chromium. Is there anything like that?
I would be very interested in this for the firefox module in Home Manager. Iâve briefly looked at this at some point but havenât really found any great solution. From what I can tell it is sometimes possible to put the XPI file somewhere and Firefox will pick it up on the next restart but I would really like some nice and simple explanation.
This article should help out with that.
Also take a look at the tor-browser-bundle derivation.
Hi, any updates for this topic?
Iâd also love to see that.
I might try my hand at this when I get the time.
Yeah, it seems quite doable. The issue Iâm concerned about is the
No automatic updates will be performed for add-ons installed using
these methods. You will have to deliver a new XPI file to your user for
each update.
part. I think this means that there would have to be regular (and
ideally scripted) updates of the Firefox plugin package set. Probably
not terribly difficult to arrange, though, especially if there is some form of
REST API for https://addons.mozilla.org/.
Is there a place like the âExternal Extensionsâ directory in Chromium but for FIrefox? Put those signed xpi in the browser/extensions
directory along side with the firefox executable binary works, but It may require to rebuild the derivation everytime, which seems to be a huge waste to the disk-space.
I donât know if there is such a directory but if there is not it should be possible to just symlink everything together instead of rebuilding.
The problem is that firefox searches the directory beside its âreal pathâ, create a browser/extensions
directory near the symlink didnât work. I have to copy the binary, which seems not a good idea.
I donât know if I explain it clearly, Iâm not good at English
Oh I realize that we have patched firefox to use the MOZ_SYSTEM_DIR
env var, which should point to a directory that contains plugins and extensions. Maybe we can make its value configurable in the firefox wrapper?
Or just put them in ~/.mozilla/extensions
, but have to get the application id. And need to find the file which can control the preference so that one donât have to enable all the extensions manually every time the configuration changes.
Oh I see. If they resolve the symlink that isnât possible.
You could symlink together the extensions in a nix store directory and then point MOZ_SYSTEM_DIR
there. Writing to the home directory (~/.mozilla
) isnât possible.
Yes, but I prefer using home-manager
for per application config.
So we can link the xpi file to ~/.mozilla/<Firefox-Application-ID>/<xpi-id>.xpi
,
- <Firefox-Application-ID> is stored in the
application.ini
in the unwrapped firefox derivation - <xpi-id> for each extension is stored in the
manifest.json
, which can be retreived by extract the xpi file,
Donât know if there is an elegant way to get the two values.
We can also store the configurations in about:config
in the home.nix
, then generate a corresponding user.js
, start firefox with --profile <path>
option and then user.js
is live in <path>
Using a /nix/store
approach still makes it possible to use home-manager. home
is inherently stateful and storing files there loses some of nixâs benefits. The biggest thing I can think of is that you cannot install two different versions of firefox with different addons at the same time. So if possible, I think a /nix/store
approach should be preferred.
I put together a quick overlay with a daily job producing a tarball. Quite rough for now but it contains the add-ons I typically use:
- cookie-autodelete
- decentraleyes
- greasemonkey
- https-everywhere
- link-cleaner
- octotree
- privacy-badger17
- reddit-enhancement-suite
- save-page-we
- styl-us
- ublock-origin
Not particularly pretty but I use it in Home Manager like so:
nixpkgs.overlays = [
(import (builtins.fetchTarball "https://gitlab.com/rycee/nixpkgs-firefox-addons/-/jobs/artifacts/master/raw/overlay.tar.gz?job=nixpkgs-overlay"))
];
home.file.".mozilla" = {
source = pkgs.buildEnv {
name = "firefox-addons";
paths = with pkgs.firefox-addons; [
cookie-autodelete
decentraleyes
greasemonkey
https-everywhere
link-cleaner
octotree
privacy-badger17
reddit-enhancement-suite
save-page-we
styl-us
ublock-origin
];
} + "/share/mozilla";
recursive = true;
};
Put together a simple Home Manager module for this overlay. It basically just wraps the example I gave in my previous post to let you put something like
programs.firefox-addons = with pkgs.firefox-addons; [
https-everywhere
privacy-badger
];
in your HM configuration. Ultimately Iâd hope to put it in the âofficialâ firefox module but Iâm not sure how to handle such 3rd party overlays in a sane manner. If anybody has ideas Iâd be happy to listen.
Lovely!
A couple of questions:
- whatâs the hash in
extensionPath
? - does this work with any AMO extension, or only ones listed somewhere in the overlay?
The hash is actually the unique Firefox application ID: Install.rdf - MozillaZine Knowledge Base
So since the application ID is hard coded it would currently only work with Firefox extensions but I guess in principle it should be possible to parametrize the application ID. Then could have, for example, a thunderbird-addons module.
Thanks! But just to be clear: itâs not just a pre-whitelisted set of extensions that can be installed, right? IIRC thatâs how the first iteration of this worked.
Well, it is absolutely possible to create and install your own extension packages. The overlay contains a simple convenience function buildFirefoxXpiAddon that can be used to download and install an XPI file. The function isnât exposed outside the overlay at the moment but this could be changed.
The extensions that are part of the daily updated overlay is basically the ones that I happen to use. Additional ones could easily be added by adding to the list of known addons. Either by making a pull request of simply sending me a list of URL slugs (e.g., the âstyl-usâ in the URL Stylus â Get this Extension for đŚ Firefox (en-US)).
When installing a new XPI file you have to go into the Firefox add-ons settings to enable it, I donât know if there is a way to bypass this easily and I think I prefer having this step remain manual anyway.