Spent entirely too much time today trying to cleanly (declaratively, #Nix-ily) have #firefox set up with my preferred prefs and extensions, before eventually giving up and writing a small Python program to hack it.

I don't actually speak Python, I suspect this is obvious to anyone reading it that does.

https://gist.github.com/telent/05acc76ba53634ccc4b873a400326dde

(Usage notes: it sets the toolkit.policies.perUserDir pref to make firefox look for policies.json in /run/user/$UID somewhere instead of in its own lib directory - because that's readonly on Nix. Then it writes the policy json in that place. One should note that /run is ephemeral, so probably need to run this on every login)

configure-firefox.py

GitHub Gist: instantly share code, notes, and snippets.

Gist
self reply

Yes, in case you were wondering: I really do configure Firefox to use Alt as the modifier for actions like cut/copy/paste instead of Ctrl. Just because I'm using PC hardware doesn't mean I'm in thrall to Windows.

I have just this moment installed Alacritty to replace Gnome Terminal and set it up to behave the same way. Now "copy" is consistently Alt-C instead of sometimes Ctrl-C and sometimes Ctrl-Shift-C

self reply

probably need to run this on every login

We can do this by making the derivation create a systemd unit file along with the script itself, then enabling that in systemd

https://github.com/telent/config-nixpkgs/commit/deb27919eb705a10f6767cbb61023cd19a6599ec

I suspect there's no way to make this fully automatic that doesn't involve changing the nixos configuration (i.e. being root), but the manual steps involved (systemctl --user enable configure-firefox) are not yet feeling too onerous.

How much further down this route can I go without giving in and learning home-manager?

add a systemd user service for configure-firefox · telent/config-nixpkgs@deb2791

I *think* this is working. After running nix-env -r -iA...

GitHub
in reply to Daniel Barlow
in reply to Thibaut
in reply to Daniel Barlow

@dan The wrapper could do exactly the same thing that your systemd unit does, or even start that unit. Like:
1) check if the configuration was already done (if configuration application is not idempotent, or to save time)
2) if not, apply the configuration OR launch the systemd service which apply the configuration
3) launch firefox (with wrapper's arguments)

in reply to Thibaut