home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

firefox: support setting search engine & adding custom engines

Open kira-bruneau opened this issue 2 years ago • 5 comments

Description

With this change, it's now possible to configure the default search engine in Firefox with programs.firefox.profiles.<name>.search.default and add custom engines with programs.firefox.profiles.<name>.search.engines.

It's also recommended to enable programs.firefox.profiles.<name>.search.force = true since Firefox will replace the symlink for the search configuration on every launch, but note that you'll loose any existing configuration by enabling this.

Here's an example of how I'm using this in my home-manager config: https://gitlab.com/kira-bruneau/home-config/-/blob/028c1a50c82f8cad2be3d6693e6c53c67bf7e7c2/package/firefox/default.nix#L9-93.

NOTE: The hash verification is only required for custom search engines, it's ignored when setting your default engine to a builtin engine, but I set this up to still generate the hash anyway to be consistent with Firefox.

Closes #2318 @pshirshov

Checklist

  • [x] Change is backwards compatible.

  • [x] Code formatted with ./format.

  • [x] Code tested through nix-shell --pure tests -A run.all.

  • [x] Test cases updated/added. See example.

  • [x] Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

~- If this PR adds a new module~

  • [x] Added myself as module maintainer. See example.

  • [x] Added myself and the module files to .github/CODEOWNERS.

kira-bruneau avatar May 29 '22 03:05 kira-bruneau

Excited to see this, thank you! Any chance it can be merged soon?

pshirshov avatar May 31 '22 14:05 pshirshov

I decided to rename the enable option to force and make it optional, so it's clearer that it isn't "enabling" search, but overriding the existing search config that Firefox writes.

kira-bruneau avatar May 31 '22 18:05 kira-bruneau

Is there any blocker for this to be merged? :(

pshirshov avatar Jun 27 '22 17:06 pshirshov

@peterhoeg

pshirshov avatar Jun 27 '22 17:06 pshirshov

@rycee , sorry about bothering you, but could you have a look at this please?

pshirshov avatar Jul 18 '22 17:07 pshirshov

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/firefox-search-engine-shortcuts/22177/5

nixos-discourse avatar Oct 05 '22 01:10 nixos-discourse

@Atemu , @ncfavier : any chance you may accept it?

pshirshov avatar Oct 14 '22 16:10 pshirshov

@kira-bruneau seems like the P/R doesn't work on macOS:

error: Package ‘mozlz4a-2018-08-23’ in /nix/store/qr489cwcx2l5b9m234g5ipqxan0mr7fd-source/pkgs/tools/compression/mozlz4a/default.nix:27 is not supported on ‘x86_64-darwin’, refusing to evaluate.

Though I don't see anything linux-specific in the python script (formula, script), do you think you may just incorporate that script into your PR?

pshirshov avatar Oct 14 '22 16:10 pshirshov

https://github.com/NixOS/nixpkgs/issues/196018

pshirshov avatar Oct 14 '22 17:10 pshirshov

https://github.com/NixOS/nixpkgs/pull/196021 - I guess that may help

pshirshov avatar Oct 14 '22 17:10 pshirshov

@pshirshov neither of us are maintainers here; we only provided feedback on the code.

Atemu avatar Oct 14 '22 17:10 Atemu

@rycee : please...

pshirshov avatar Oct 20 '22 22:10 pshirshov

Thanks! Fixed a few minor issues and merged to master now.

I think some of the code could benefit by having more let bindings to make it a bit more understandable, see e.g. the definition of orderedEngineList, but it's OK for now.

rycee avatar Oct 22 '22 19:10 rycee

To be honest, even as it is it's totally understandable and it's a real game changer. Many thanks!

pshirshov avatar Oct 22 '22 19:10 pshirshov

Indeed, this is a very nice feature and @kira-bruneau did a great job implementing it! So, I hope my comment above does not seem too negative, it was meant purely as constructive criticism.

rycee avatar Oct 22 '22 22:10 rycee

@rycee Yeah... I was worried it was too messy / hard to follow :sweat_smile:, but there's also just a lot going on to get this to work. I'll try to clean it up some more. Would it make sense to try to split this into a separate file?

kira-bruneau avatar Oct 24 '22 02:10 kira-bruneau

@kira-bruneau No need for a separate file, I think. It seems to me the thing that would help readability the most in this case is "naming things".

For example, instead of having, loosely modeled on orderedEngineList,

imap (i: x: long expression) xs ++ map (y: long expression) (expression)

one could try doing something like

let
  descriptiveName1 = i: x: long expression;
  descriptiveName2 = y: long expression;
  descriptiveName3 = expression;
in
  imap descriptiveName1 xs ++ map descriptiveName2 descriptiveName3

the long expressions themselves may benefit from let bindings, in which case the variable could be placed either within the function definition or on the same level as descriptiveNameX. Typically I would move the definition out of the function unless it uses a function argument.

rycee avatar Oct 24 '22 10:10 rycee