firefox: fix search options without a default engine

This commit is contained in:
Kira Bruneau 2023-01-06 19:13:13 -05:00 committed by Robert Helgesson
parent c7c69ec405
commit 564b82b354
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
3 changed files with 93 additions and 10 deletions

View file

@ -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
'';
};

View file

@ -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
}

View file

@ -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}
'';
}