diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 7eb06465a..797bb1f20 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -653,15 +653,21 @@ in { + "from outside of ${appName} is a malicious act, and will be responded " + "to accordingly."; - salt = profile.path + profile.search.default - + disclaimer "Firefox"; + salt = if profile.search.default != null then + profile.path + profile.search.default + disclaimer "Firefox" + else + null; in pkgs.runCommand "search.json.mozlz4" { nativeBuildInputs = with pkgs; [ mozlz4a openssl ]; json = builtins.toJSON settings; inherit salt; } '' - export hash=$(echo -n "$salt" | openssl dgst -sha256 -binary | base64) - mozlz4a <(substituteStream json search.json.in --subst-var hash) "$out" + if [[ -n $salt ]]; then + export hash=$(echo -n "$salt" | openssl dgst -sha256 -binary | base64) + mozlz4a <(substituteStream json search.json.in --subst-var hash) "$out" + else + mozlz4a <(echo "$json") "$out" + fi ''; }; diff --git a/tests/modules/programs/firefox/profile-settings-expected-search-without-default.json b/tests/modules/programs/firefox/profile-settings-expected-search-without-default.json new file mode 100644 index 000000000..b845dad42 --- /dev/null +++ b/tests/modules/programs/firefox/profile-settings-expected-search-without-default.json @@ -0,0 +1,41 @@ +{ + "engines": [ + { + "_isAppProvided": true, + "_metaData": { + "order": 1 + }, + "_name": "Google" + }, + { + "_definedAliases": [ + "@np" + ], + "_isAppProvided": false, + "_loadPath": "[home-manager]/programs.firefox.profiles.searchWithoutDefault.search.engines.\"Nix Packages\"", + "_metaData": { + "order": 2 + }, + "_name": "Nix Packages", + "_urls": [ + { + "params": [ + { + "name": "type", + "value": "packages" + }, + { + "name": "query", + "value": "{searchTerms}" + } + ], + "template": "https://search.nixos.org/packages" + } + ] + } + ], + "metaData": { + "useSavedOrder": true + }, + "version": 6 +} diff --git a/tests/modules/programs/firefox/profile-settings.nix b/tests/modules/programs/firefox/profile-settings.nix index 278f3dbb9..3b5d6cc81 100644 --- a/tests/modules/programs/firefox/profile-settings.nix +++ b/tests/modules/programs/firefox/profile-settings.nix @@ -109,6 +109,33 @@ lib.mkIf config.test.enableBig { }; }; }; + + profiles.searchWithoutDefault = { + id = 4; + search = { + force = true; + order = [ "Google" "Nix Packages" ]; + engines = { + "Nix Packages" = { + urls = [{ + template = "https://search.nixos.org/packages"; + params = [ + { + name = "type"; + value = "packages"; + } + { + name = "query"; + value = "{searchTerms}"; + } + ]; + }]; + + definedAliases = [ "@np" ]; + }; + }; + }; + }; }; nixpkgs.overlays = [ @@ -151,14 +178,23 @@ lib.mkIf config.test.enableBig { $bookmarksFile \ ${./profile-settings-expected-bookmarks.html} - compressedSearch=$(normalizeStorePaths \ - home-files/.mozilla/firefox/search/search.json.mozlz4) + function assertFirefoxSearchContent() { + compressedSearch=$(normalizeStorePaths "$1") - decompressedSearch=$(dirname $compressedSearch)/search.json - ${pkgs.mozlz4a}/bin/mozlz4a -d "$compressedSearch" >(${pkgs.jq}/bin/jq . > "$decompressedSearch") + decompressedSearch=$(dirname $compressedSearch)/search.json + ${pkgs.mozlz4a}/bin/mozlz4a -d "$compressedSearch" >(${pkgs.jq}/bin/jq . > "$decompressedSearch") - assertFileContent \ - $decompressedSearch \ + assertFileContent \ + $decompressedSearch \ + "$2" + } + + assertFirefoxSearchContent \ + home-files/.mozilla/firefox/search/search.json.mozlz4 \ ${./profile-settings-expected-search.json} + + assertFirefoxSearchContent \ + home-files/.mozilla/firefox/searchWithoutDefault/search.json.mozlz4 \ + ${./profile-settings-expected-search-without-default.json} ''; }