From 298aa410eb77ec155b7297db0932642a8dd232df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Mon, 12 Feb 2024 10:27:16 +0100 Subject: [PATCH] refacor: firefox search engine settings --- modules/programs/firefox.nix | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 041a1a4..09c637b 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -29,19 +29,36 @@ in ); }; }; - setSearchEngines = mkEnableOption "firefox search engines"; + package = mkOption { + type = types.package; + default = pkgs.firefox; + example = pkgs.firefox-esr; + }; }; config = mkIf cfg.enable { home-manager.users.moritz.programs.firefox = { enable = true; - policies = mkIf cfg.setSearchEngines { - SearchEngines = { - Default = "Kagi"; - Remove = [ "Google" "Amazon.de" "Bing" ]; + policies = + let + removeExtensions = [ "Google" "Amazon.de" "Bing" "Amazon" "Wikipedia (en)" "Wikipedia (de)" ]; + convertName = name: + let + lower = toLower name; + escaped = replaceStrings [ "." ] [ "dot" ] lower; + sanitized = head (splitString " " escaped); + in + "${sanitized}@search.mozilla.org"; + in + { + SearchEngines = mkIf (hasInfix "esr" cfg.package) { + Default = "Kagi"; + Remove = removeExtensions; + }; + ExtensionSettings = genAttrs + (map convertName removeExtensions) + (_: { installation_mode = "blocked"; }); }; - }; - package = if cfg.setSearchEngines then pkgs.firefox-esr else pkgs.firefox; profiles."default" = { extraConfig = mkIf cfg.arkenfox.enable '' // Arkenfox user.js