Fixing Firefox#
Wed, 06 May 2020 08:52:30 +0000
You can interpret "fixing" here in any of its popular senses.
Presenting one approach for getting from freshly installed Firefox to something you'd actually want to use (preferences, extensions, etc) without tedious manual configuration.
The mechanism:
- any prefs (these correspond to the options in
about:config
) we put in theuser.js
file in the current profile will override other values of the same options set anywhere else. We need to parse~/.mozilla/firefox/profiles.ini
, find the current profile, and write that file
- to ensure that extensions are installed, we can use the Enterprise
Policies
Firefox feature : write a
policies.json
file that "goes into a directory calleddistribution
within the Firefox installation directory."
- that doesn't help us directly, as the said directory on Nix is
within
/nix/store/
which is read-only - but: there's a pref to make Firefox look for it somewhere else. Iftoolkit.policies.perUserDir
is true, it will instead search in/run/user/nnn/firefox
- see bug 1583466
- So: we have a small Python program that finds the profile and writes the prefs js, then writes the policies.json into
/run/user/1000/firefox/
- This directory is ephemeral - for one thing it's on a ramdisk, and
for another there's systemd magic that wipes it out when you
logout. So we need a way to recreate it on login, and what better
than a systemd
service?
If our package derivation puts this file in
$out/share/systemd/user/
then it will end up somewhere systemd can see it.
So it's not wholly automatic but it's pretty close: after running
nix-env -r -iA nixos.desktop
- which is my usual way of setting up
my user environment - I needed to do systemctl --user enable
configure-firefox
. Yes, I could probably put that in my
nixos configuration.nix but then I've coupled my per-user and per-host
configuration and I'm not completely certain I want to do that.