From ce5431591cdce666fc9a436863fc60c0a34ba00b Mon Sep 17 00:00:00 2001 From: colin Date: Fri, 1 Jul 2022 01:04:19 -0700 Subject: [PATCH] patch Firefox so that we can properly set the default search engine i'll probably (partially) revert this and switch to librewolf instead. Firefox takes about 1hr to build. --- modules/universal/home-manager.nix | 62 +++++++++++++++++-- .../allow-searchengines-non-esr.patch | 13 ++++ pkgs/firefox-unwrapped/default.nix | 10 +++ pkgs/overlay.nix | 2 + 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 pkgs/firefox-unwrapped/allow-searchengines-non-esr.patch create mode 100644 pkgs/firefox-unwrapped/default.nix diff --git a/modules/universal/home-manager.nix b/modules/universal/home-manager.nix index d2dd7ea1..00517c6c 100644 --- a/modules/universal/home-manager.nix +++ b/modules/universal/home-manager.nix @@ -143,9 +143,66 @@ in ''; }; + # librewolf is able to set the default search engine by using mozilla policies. + # they do this by removing the "enterprise" gate on some features and building a patched Firefox. + # some of the settings below assume those patches have been applied to firefox. + # see: https://gitlab.com/librewolf-community/settings/-/blob/master/distribution/policies.json firefox = lib.mkIf (sysconfig.colinsane.gui.enable) { enable = true; + # https://discourse.nixos.org/t/infinite-recursion-with-wrapfirefox/11579 + package = pkgs.wrapFirefox pkgs.firefox-unwrapped { + extraPolicies = { + DisableAppUpdate = true; + DisablePocket = true; + DisableFirefoxStudies = true; + DisableTelemetry = true; + DisableFeedbackCommands = true; + Extensions = { + Uninstall = [ + "google@search.mozilla.org" + "bing@search.mozilla.org" + "amazondotcom@search.mozilla.org" + "ebay@search.mozilla.org" + "twitter@search.mozilla.org" + ]; + }; + SearchEngines = { + Default = "DuckDuckGo"; + Remove = [ + "Google" + "Bing" + "Amazon.com" + "eBay" + "Twitter" + ]; + Add = [ + { + Name = "DuckDuckGo Lite"; + Description = "Minimal, ad-free version of DuckDuckGo"; + Alias = ""; + Method = "POST"; + URLTemplate = "https://duckduckgo.com/lite/?q={searchTerms}"; + PostData = "q={searchTerms}"; + } + ]; + }; + }; + + extraPrefs = '' + lockPref("devtools.theme","dark"); + lockPref("browser.search.defaultenginename","DuckDuckGo"); + lockPref("browser.search.selectedEngine","DuckDuckGo"); + lockPref("browser.search.defaulturl","https://duckduckgo.com/?q="); + lockPref("browser.search.searchEnginesURL","https://duckduckgo.com/?q="); + lockPref("browser.search.selectedEngineInDialog","DuckDuckGo"); + lockPref("browser.search.hiddenOneOffs","Google,eBay,Yahoo,Bing,Amazon.com,Twitter"); + lockPref("browser.search.update",false); + lockPref("browser.urlbar.update2.engineAliasRefresh",false); + lockPref("browser.urlbar.update2.oneOffsRefresh",false); + ''; + }; + profiles.default = { bookmarks = { fed_uninsane.url = "https://fed.uninsane.org/"; @@ -156,11 +213,6 @@ in }; }; - # firefox profile support seems to be broken :shrug: - # profiles.other = { - # id = 2; - # }; - # NB: these must be manually enabled in the Firefox settings on first start # extensions can be found here: https://gitlab.com/rycee/nur-expressions/-/blob/master/pkgs/firefox-addons/addons.json extensions = let diff --git a/pkgs/firefox-unwrapped/allow-searchengines-non-esr.patch b/pkgs/firefox-unwrapped/allow-searchengines-non-esr.patch new file mode 100644 index 00000000..6418416b --- /dev/null +++ b/pkgs/firefox-unwrapped/allow-searchengines-non-esr.patch @@ -0,0 +1,13 @@ +diff --git a/browser/components/enterprisepolicies/schemas/policies-schema.json b/browser/components/enterprisepolicies/schemas/policies-schema.json +index d436cf1ca1..ecd6e53b9e 100644 +--- a/browser/components/enterprisepolicies/schemas/policies-schema.json ++++ b/browser/components/enterprisepolicies/schemas/policies-schema.json +@@ -1074,7 +1074,7 @@ + }, + + "SearchEngines": { +- "enterprise_only": true, ++ "enterprise_only": false, + + "type": "object", + "properties": { diff --git a/pkgs/firefox-unwrapped/default.nix b/pkgs/firefox-unwrapped/default.nix new file mode 100644 index 00000000..70bfee38 --- /dev/null +++ b/pkgs/firefox-unwrapped/default.nix @@ -0,0 +1,10 @@ +{ pkgs }: + +(pkgs.firefox-unwrapped.overrideAttrs (upstream: { + # NB: firefox takes about 1hr to build on my 24-thread ryzen desktop + patches = (upstream.patches or []) ++ [ + # see https://gitlab.com/librewolf-community/browser/source/-/blob/main/patches/sed-patches/allow-searchengines-non-esr.patch + ./allow-searchengines-non-esr.patch + ]; +})) + diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index e8a6f7b5..ecb7ac2e 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -18,6 +18,8 @@ pleroma = prev.callPackage ./pleroma { }; # jackett doesn't allow customization of the bind address: this will probably always be here. jackett = prev.callPackage ./jackett { pkgs = prev; }; + # mozilla keeps nerfing itself and removing configuration options + firefox-unwrapped = prev.callPackage ./firefox-unwrapped { pkgs = prev; }; # fix abrupt HDD poweroffs as during reboot. patching systemd requires rebuilding nearly every package. # systemd = import ./pkgs/systemd { pkgs = prev; };