Declare Firefox extensions and settings

This is very cool! Well done, especially since you’re new to the ecosystem.
Since you’ve looked at home-manager and the NUR, I echo the statements here that using the Firefox module is great once you get over the hump of setting it up.

The best example I’ve seen (and stolen from) is gvolpe’s nix config. Their Firefox module is here: https://github.com/gvolpe/nix-config/blob/6feb7e4f47e74a8e3befd2efb423d9232f522ccd/home/programs/browsers/firefox.nix

It also allows you to use all of rycee’s autoupdating extensions, listed in this (huge) file: https://github.com/nix-community/nur-combined/blob/cac5a762ec7c40a8489e8ba4efa4820ad4b23575/repos/rycee/pkgs/firefox-addons/addons.json

If you have specific questions getting this setup with flakes, please ask!

2 Likes

Hello @billewanick, thanks a bunch for your post. I haven’t delved into the NUR yet, because I didn’t feel the need for it and also because I am uncertain on how trustworthy and reliable it is.

Its Readme states: " [The NUR] provides access to user repositories […]. In contrast to Nixpkgs, packages are built from source and are not reviewed by any Nixpkgs member."

Since you kindly offered to help, I’d like to take the opportunity and benefit from your experience by asking for more general information on the NUR, like how it is maintained, who can submit packages to it and how likely it is to break something if it is used. (In general, I prefer to stick to official repositories and avoid using third-party ones. So far I have had very good experiences with this strategy.) Thanks in advance for sharing your insights!

That’s great stuff! I came to the same conclusion regarding nur the last time I looked at it, and didn’t bother looking into how to do it manually. This works like a charm! :clap:

2 Likes

@sleepy what if a user would like to pin a specific extension? Is there an attribute for it?

You can use a versioned url.

Did anyone figured out how to declaratively configure the invidual firefox extensions?

I managed to configure ublock-origin to my liking:

but trying the same method for libredirect doesn’t work even though the configuration is set in the policies:

I had a hypothesis that maybe the extension wipes it’s config on deployment, but trying to deploy the policies on top of configured firefox also doesn’t work… Maybe the extension has to explicitly support this kind of configuration?


Asked upstream on Firefox configuration via `policies.json` on NixOS? · Issue #905 · libredirect/browser_extension · GitHub

2 Likes

This is how I installed a custom extension from https://addons.mozilla.org via nix that isn’t available in the NUR (with version pinning and no automatic update):

2 Likes

I created a script for retrieving the ID and hope someone else finds it useful as well: GitHub - tupakkatapa/mozid: Retrieve Firefox add-on IDs.

11 Likes

Great!

Here are the ones I use

(extension "noscript" "{73a6fe31-595d-460b-a920-fcc0f8843232}")
(extension "ublock-origin" "uBlock0@raymondhill.net")
(extension "undoclosetabbutton" "{4853d046-c5a3-436b-bc36-220fd935ee1d}")
(extension "temporary-containers-plus" "{1ea2fa75-677e-4702-b06a-50fc7d06fe7e}")
(extension "single-file" "{531906d3-e22f-4a6c-a102-8057b88a1a63}")
(extension "add-custom-search-engine" "{af37054b-3ace-46a2-ac59-709e4412bec6}")

hey guys, did all of this stopped working for you just this morning? thanks in advance!!

EDIT: may 13th, still no worky :frowning:

Hi all,

I’m still relatively new to NixOS but I saw a cool lightning talk from Nixcon 2023 about configuring single site Firefox VMs in NixOS

It did mention the capacity to declare addons and I’m wondering if scripting the settings might potentially work here

On a related note, I’ve noticed recently that Firefox has been changing things around a bit. I could have sworn that there was an in-house browser option to set up profiles but it went missing in Zen and Firefox a month or two ago. To get profiles to work, i had to run firefox/Zen at the command line with the -p flag to trigger the profile manager, set the profiles I want, and then bind profiles to keyboard shortcuts in Sway to open up the profile I wanted. Makes me wonder if they’ll get rid of profiles completely in the future, so it was good to see this video suggest another way to customize firefox in a more agnostic manner

3 Likes

My favourite ones which allow me to type @np and @no for searching NixOS options and NixOS packages from the URL line.

so I can type ‘@no systemd’ and press enter :slight_smile:

	programs = {
		firefox = {
			policies = {
				SearchEngines = {
					Add = [
						{
							Alias = "@np";
							Description = "Search in NixOS Packages";
							IconURL = "https://nixos.org/favicon.png";
							Method = "GET";
							Name = "NixOS Packages";
							URLTemplate = "https://search.nixos.org/packages?from=0&size=200&sort=relevance&type=packages&query={searchTerms}";
						}
						{
							Alias = "@no";
							Description = "Search in NixOS Options";
							IconURL = "https://nixos.org/favicon.png";
							Method = "GET";
							Name = "NixOS Options";
							URLTemplate = "https://search.nixos.org/options?from=0&size=200&sort=relevance&type=packages&query={searchTerms}";
						}
					];
				};
			};
		};
	};
5 Likes

That only works if programs.firefox.package is set to pkgs.firefox-esr or pkgs.firefox-esr-128-unwrapped. policy-templates | Policy Templates for Firefox

2 Likes

Sorry, I forgot to mention that. I use ESR because that is so handy though! I have shortcuts to other search engines too. I wonder why it’s not supported in the normal releases.

I only have one issue with ESR and that is that it doesn’t register as the default Web Browser on XFCE4. I’ve never managed to sort that.

There’s also the Home Manager option programs.firefox.profiles.<name>.search.engines, for user-level configuration of search engines with any Firefox release channel.

1 Like

Presumably if home-manager can configure the search engines in any version, then it should also be possible without home-manager. :man_shrugging:t2:

The technical approaches are different. Home Manager writes to the user’s profile, but the NixOS module writes to a system-wide (well, that’s upstream’s intent; of course on NixOS this is just another path in the Nix store) policy file. Only the ESR releases permit the latter.

It doesn’t really work that nice.

It changed again! policy-templates | Policy Templates for Firefox. You can now configure search engines on Firefox 139 and above! It’s only beta as of now but you can already use it in firefox-beta-bin, firefox-devedition, firefox-devedition-bin, firefox-beta-bin-unwrapped and firefox-devedition-bin-unwrapped. NixOS Search

2 Likes

Just thought I’d add if anyone else is googling for this: if you have ExtensionSettings."*".installation_mode = "blocked", go to the firefox addon store and try to add an extension; it should pop up with the ID you need :slight_smile:.
Can’t copy-paste it but it might still be easier than about:support.

2 Likes