diff --git a/modules/programs/firefox/profiles/search.nix b/modules/programs/firefox/profiles/search.nix index 074692b48..82c346503 100644 --- a/modules/programs/firefox/profiles/search.nix +++ b/modules/programs/firefox/profiles/search.nix @@ -57,7 +57,10 @@ let in if requiredInput.isAppProvided then requiredInput else - processCustomEngineInput (input // requiredInput); + pipe (input // requiredInput) [ + migrateEngineToV11 + processCustomEngineInput + ]; buildEngineConfig = name: input: mapAttrs' (name: value: { @@ -91,7 +94,7 @@ let }; settings = { - version = 7; + version = 11; engines = sortEngineConfigs (mapAttrs buildEngineConfig engineInput); metaData = optionalAttrs (config.default != null) { @@ -323,6 +326,23 @@ let }' instead of '${engine}'" engineNameToId.${engine} else engine; + + migrateEngineToV11 = engine: + engine // lib.optionalAttrs (engine ? iconMapObj) { + iconMapObj = mapAttrs' (name: value: + let nameToIntResult = builtins.tryEval (toInt name); + in { + name = if nameToIntResult.success then + name + else + let size = toString (builtins.fromJSON name).width; + in warn + "JSON object names for 'iconMapObj' are deprecated, use '${size}' instead of '${name}'" + size; + + inherit value; + }) engine.iconMapObj; + }; in { imports = [ (pkgs.path + "/nixos/modules/misc/meta.nix") ]; diff --git a/tests/modules/programs/firefox/profiles/search/default.nix b/tests/modules/programs/firefox/profiles/search/default.nix index a2a9a526f..1818ccc4f 100644 --- a/tests/modules/programs/firefox/profiles/search/default.nix +++ b/tests/modules/programs/firefox/profiles/search/default.nix @@ -142,6 +142,27 @@ in { }; }; + migrateIconsV11 = { + id = 3; + search = { + force = true; + engines = { + nixos-wiki = { + name = "NixOS Wiki"; + + urls = [{ + template = + "https://wiki.nixos.org/w/index.php?search={searchTerms}"; + }]; + + iconMapObj."{\"width\":16,\"height\":16}" = + "https://wiki.nixos.org/favicon.ico"; + + definedAliases = [ "@nw" ]; + }; + }; + }; + }; }; } // { nmt.script = let @@ -187,6 +208,10 @@ in { assertFirefoxSearchContent \ home-files/${cfg.configPath}/migrateSearchV7/search.json.mozlz4 \ ${withName ./expected-migrate-search-v7.json} + + assertFirefoxSearchContent \ + home-files/${cfg.configPath}/migrateIconsV11/search.json.mozlz4 \ + ${withName ./expected-migrate-icons-v11.json} ''; }); } diff --git a/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v11.json b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v11.json new file mode 100644 index 000000000..c3d5c15f2 --- /dev/null +++ b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v11.json @@ -0,0 +1,26 @@ +{ + "engines": [ + { + "_definedAliases": [ + "@nw" + ], + "_iconMapObj": { + "16": "https://wiki.nixos.org/favicon.ico" + }, + "_isAppProvided": false, + "_loadPath": "[home-manager]/programs.@name@.profiles.migrateIconsV11.search.engines.nixos-wiki", + "_metaData": {}, + "_name": "NixOS Wiki", + "_urls": [ + { + "template": "https://wiki.nixos.org/w/index.php?search={searchTerms}" + } + ], + "id": "nixos-wiki" + } + ], + "metaData": { + "useSavedOrder": false + }, + "version": 11 +} diff --git a/tests/modules/programs/firefox/profiles/search/expected-migrate-search-v7.json b/tests/modules/programs/firefox/profiles/search/expected-migrate-search-v7.json index 850afc6e3..123eeaf6f 100644 --- a/tests/modules/programs/firefox/profiles/search/expected-migrate-search-v7.json +++ b/tests/modules/programs/firefox/profiles/search/expected-migrate-search-v7.json @@ -75,5 +75,5 @@ "privateDefaultEngineIdHash": "@privateHash@", "useSavedOrder": true }, - "version": 7 + "version": 11 } diff --git a/tests/modules/programs/firefox/profiles/search/expected-search-without-default.json b/tests/modules/programs/firefox/profiles/search/expected-search-without-default.json index 2ba4691d9..42eea4e71 100644 --- a/tests/modules/programs/firefox/profiles/search/expected-search-without-default.json +++ b/tests/modules/programs/firefox/profiles/search/expected-search-without-default.json @@ -38,5 +38,5 @@ "metaData": { "useSavedOrder": true }, - "version": 7 + "version": 11 } diff --git a/tests/modules/programs/firefox/profiles/search/expected-search.json b/tests/modules/programs/firefox/profiles/search/expected-search.json index 8688aea15..d7c0ffece 100644 --- a/tests/modules/programs/firefox/profiles/search/expected-search.json +++ b/tests/modules/programs/firefox/profiles/search/expected-search.json @@ -75,5 +75,5 @@ "privateDefaultEngineIdHash": "@privateHash@", "useSavedOrder": true }, - "version": 7 + "version": 11 }