Is there a way to configure Firefox search engine shortcuts using NixOS in a declarative way (using flakes if that matters)?
Maybe there is something in home-manger, maybe to this?
Yes and also no. The firefox profile settings are indeed where you should do that, but it’s a bit silly.
Specifically, the generic configuration interface for Firefox is the user.js
file, which is allowed to modify any number of settings from about:config
. home-manager’s settings
option sets these.
Sadly, search engines are a type of “plugin” (a term used almost nowhere else in Firefox, and actually “search plugins” are their own thing entirely). So while you can set the selected default, you can’t add a new one with just user.js
.
The mozilla docs document a browser.search.defaulturl
which presumably at least was used for this at one point. I think last time I tried this didn’t work, sadly.
Firefox also creates a file that contains all the search plugins which you might be able to overwrite, but iirc it isn’t human readable and I couldn’t make it use a backed up version either.
I have this in my config, no idea if it actually works or it I just left it at that after trying for a week: https://github.com/TLATER/dotfiles/blob/110610394e709dac8abd412a5876abd9bf5f9590/nixpkgs/configurations/graphical-programs/firefox.nix#L96
Generally, Firefox seems to be trying to phase out these configuration files, too, sadly. If I was conspiratorially minded I’d assume they don’t want you removing pocket and default search engines because they make a fair bit of their funding from those.
More reasonably, all the search suggestion APIs have their own quirks so just giving Firefox a template URL isn’t enough anymore. They needed something more complex, and nobody cared to write user-facing configuration APIs for this, so now we’re stuck with an auto-updating script that’s stored in an sqlite database for some reason.
All web browsers suck these days
Not all the ways to search. I heavily use bookmarks to search (actually called keyword searches), the feature has been in FF for ages. I did not manage to put it in my hm config yet but, you should be able to add them like any other bookmark.
Also, I have not looked that deep info it, but this seems also related firefox: support setting search engine & adding custom engines by kira-bruneau · Pull Request #2984 · nix-community/home-manager · GitHub
Oh yep, I’ve been updating the PR every so often for my flake and haven’t run into any issues since I started it: package/firefox/default.nix · b77196afee972ed712dc96ba1cb85da3351de9e7 · Kira Bruneau / nixos-config · GitLab.
It’s just blocked on a reviewer right now (I’m not quite sure who to ping and pshirshov has already sent out a couple). It’s completely understandable though because it adds a lot of complexity to the module.
If you want to try it out, you can point your flake to my branch like I’ve been doing in my nixos config: flake.nix · 1a2cd31b3b28ded47ee3296c5659036ce87a892a · Kira Bruneau / nixos-config · GitLab