diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index e63a72670..6a3ab656c 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -444,6 +444,15 @@ in { ''; }; + privateDefault = mkOption { + type = with types; nullOr str; + default = null; + example = "DuckDuckGo"; + description = '' + The default search engine used in the Private Browsing. + ''; + }; + order = mkOption { type = with types; uniq (listOf str); default = [ ]; @@ -675,8 +684,8 @@ in { }; "${profilesPath}/${profile.path}/search.json.mozlz4" = mkIf - (profile.search.default != null || profile.search.order != [ ] - || profile.search.engines != { }) { + (profile.search.default != null || profile.search.privateDefault != null + || profile.search.order != [ ] || profile.search.engines != { }) { force = profile.search.force; source = let settings = { @@ -767,12 +776,18 @@ in { # engine if it's not in profile.search.engines ${profile.search.default} = profile.search.engines.${profile.search.default} or { }; + } // { + ${profile.search.privateDefault} = + profile.search.engines.${profile.search.privateDefault} or { }; }; in sortEngineConfigs (mapAttrs buildEngineConfig engineInput); metaData = optionalAttrs (profile.search.default != null) { current = profile.search.default; hash = "@hash@"; + } // optionalAttrs (profile.search.privateDefault != null) { + private = profile.search.privateDefault; + privateHash = "@privateHash@"; } // { useSavedOrder = profile.search.order != [ ]; }; @@ -794,14 +809,21 @@ in { profile.path + profile.search.default + disclaimer "Firefox" else null; + + privateSalt = if profile.search.privateDefault != null then + profile.path + profile.search.privateDefault + + disclaimer "Firefox" + else + null; in pkgs.runCommand "search.json.mozlz4" { nativeBuildInputs = with pkgs; [ mozlz4a openssl ]; json = builtins.toJSON settings; - inherit salt; + inherit salt privateSalt; } '' if [[ -n $salt ]]; then export hash=$(echo -n "$salt" | openssl dgst -sha256 -binary | base64) - mozlz4a <(substituteStream json search.json.in --subst-var hash) "$out" + export privateHash=$(echo -n "$privateSalt" | openssl dgst -sha256 -binary | base64) + mozlz4a <(substituteStream json search.json.in --subst-var hash --subst-var privateHash) "$out" else mozlz4a <(echo "$json") "$out" fi diff --git a/tests/modules/programs/firefox/profile-settings-expected-search.json b/tests/modules/programs/firefox/profile-settings-expected-search.json index ceee27ee6..f17a0b91e 100644 --- a/tests/modules/programs/firefox/profile-settings-expected-search.json +++ b/tests/modules/programs/firefox/profile-settings-expected-search.json @@ -67,8 +67,10 @@ } ], "metaData": { - "current": "DuckDuckGo", - "hash": "BWvqUiaCuMJ20lbymFf2dqzWyl1cgm1LZhhdWNEp0Cc=", + "current": "Google", + "hash": "IRmKVSQlAYnvLO8kdZyNUR/g5hzVn4++T0PLPGm+kZk=", + "private": "DuckDuckGo", + "privateHash": "BWvqUiaCuMJ20lbymFf2dqzWyl1cgm1LZhhdWNEp0Cc=", "useSavedOrder": true }, "version": 6 diff --git a/tests/modules/programs/firefox/profile-settings.nix b/tests/modules/programs/firefox/profile-settings.nix index 6529a1bb2..94fa9436e 100644 --- a/tests/modules/programs/firefox/profile-settings.nix +++ b/tests/modules/programs/firefox/profile-settings.nix @@ -75,7 +75,8 @@ id = 3; search = { force = true; - default = "DuckDuckGo"; + default = "Google"; + privateDefault = "DuckDuckGo"; order = [ "Nix Packages" "NixOS Wiki" ]; engines = { "Nix Packages" = {