From 8b629b5424dd2b10ff5cbca7fa52fa66ef33a196 Mon Sep 17 00:00:00 2001 From: Kira Bruneau Date: Tue, 18 Mar 2025 17:00:40 -0400 Subject: [PATCH] firefox: migrate search config to v12 --- modules/programs/firefox/profiles/search.nix | 50 ++++++++++------- .../firefox/profiles/search/default.nix | 40 ++++++++++++-- .../search/expected-migrate-icons-v11.json | 2 +- .../search/expected-migrate-icons-v12.json | 36 +++++++++++++ .../search/expected-migrate-icons.json | 54 +++++++++++++++++++ .../search/expected-migrate-search-v7.json | 11 ++-- .../expected-search-without-default.json | 2 +- .../profiles/search/expected-search.json | 14 ++--- 8 files changed, 176 insertions(+), 33 deletions(-) create mode 100644 tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v12.json create mode 100644 tests/modules/programs/firefox/profiles/search/expected-migrate-icons.json diff --git a/modules/programs/firefox/profiles/search.nix b/modules/programs/firefox/profiles/search.nix index 82c346503..5b56aba1b 100644 --- a/modules/programs/firefox/profiles/search.nix +++ b/modules/programs/firefox/profiles/search.nix @@ -12,11 +12,8 @@ let "name" "isAppProvided" "loadPath" - "hasPreferredIcon" "updateInterval" "updateURL" - "iconUpdateURL" - "iconURL" "iconMapObj" "metaData" "orderHint" @@ -26,25 +23,27 @@ let searchForm = "__searchForm"; }; + # Convenience to specify absolute path to icon + iconUrl = icon: + if isPath icon || hasPrefix "/" icon then "file://${icon}" else icon; + processCustomEngineInput = input: { name = input.id; - } // (removeAttrs input [ "icon" ]) // optionalAttrs (input ? icon) { - # Convenience to specify absolute path to icon - iconURL = "file://${input.icon}"; - } // (optionalAttrs (input ? iconUpdateURL) { - # Convenience to default iconURL to iconUpdateURL so - # the icon is immediately downloaded from the URL - iconURL = input.iconURL or input.iconUpdateURL; + } // (removeAttrs input [ "icon" ]) + // optionalAttrs (input ? icon || input ? iconMapObj) { + iconMapObj = mapAttrs (name: iconUrl) ((optionalAttrs (input ? icon) { + # Convenience to specify single icon instead of map + "16" = input.icon; + }) // (input.iconMapObj or { })); } // { # Required for custom engine configurations, loadPaths # are unique identifiers that are generally formatted # like: [source]/path/to/engine.xml loadPath = "[home-manager]/${ - concatStringsSep "." (map strings.escapeNixIdentifier - (modulePath ++ [ "engines" input.id ])) + lib.showAttrPath (modulePath ++ [ "engines" input.id ]) }"; - }); + }; processEngineInput = id: input: let @@ -59,6 +58,7 @@ let else pipe (input // requiredInput) [ migrateEngineToV11 + migrateEngineToV12 processCustomEngineInput ]; @@ -94,7 +94,7 @@ let }; settings = { - version = 11; + version = 12; engines = sortEngineConfigs (mapAttrs buildEngineConfig engineInput); metaData = optionalAttrs (config.default != null) { @@ -343,6 +343,21 @@ let inherit value; }) engine.iconMapObj; }; + + migrateEngineToV12 = engine: + let + iconMapObj = optionalAttrs (engine ? iconURL) { + "16" = warn "'iconURL' is deprecated, use 'icon = ${ + strings.escapeNixString engine.iconURL + }' instead" engine.iconURL; + } // optionalAttrs (engine ? iconUpdateURL) { + "16" = warn "'iconUpdateURL' is deprecated, use 'icon = ${ + strings.escapeNixString engine.iconUpdateURL + }' instead" engine.iconUpdateURL; + } // (engine.iconMapObj or { }); + in throwIf (engine ? hasPreferredIcon) "hasPreferredIcon has been removed" + (removeAttrs engine [ "iconURL" "iconUpdateURL" ]) + // lib.optionalAttrs (iconMapObj != { }) { inherit iconMapObj; }; in { imports = [ (pkgs.path + "/nixos/modules/misc/meta.nix") ]; @@ -430,9 +445,8 @@ in { nixos-wiki = { name = "NixOS Wiki"; - urls = [{ template = "https://wiki.nixos.org/index.php?search={searchTerms}"; }]; - iconUpdateURL = "https://wiki.nixos.org/favicon.png"; - updateInterval = 24 * 60 * 60 * 1000; # every day + urls = [{ template = "https://wiki.nixos.org/w/index.php?search={searchTerms}"; }]; + iconMapObj."16" = "https://wiki.nixos.org/favicon.ico"; definedAliases = [ "@nw" ]; }; @@ -446,7 +460,7 @@ in { only have {var}`metaData` specified will be treated as builtin to ${appName}. - See [SearchEngine.jsm](https://searchfox.org/mozilla-central/rev/669329e284f8e8e2bb28090617192ca9b4ef3380/toolkit/components/search/SearchEngine.jsm#1138-1177) + See [SearchEngine.jsm](https://searchfox.org/mozilla-central/rev/e3f42ec9320748b2aab3d474d1e47075def9000c/toolkit/components/search/SearchEngine.sys.mjs#890-923) in ${appName}'s source for available options. We maintain a mapping to let you specify all options in the referenced link without underscores, but it may fall out of date with future diff --git a/tests/modules/programs/firefox/profiles/search/default.nix b/tests/modules/programs/firefox/profiles/search/default.nix index 1818ccc4f..76baf1230 100644 --- a/tests/modules/programs/firefox/profiles/search/default.nix +++ b/tests/modules/programs/firefox/profiles/search/default.nix @@ -55,10 +55,10 @@ in { urls = [{ template = - "https://wiki.nixos.org/index.php?search={searchTerms}"; + "https://wiki.nixos.org/w/index.php?search={searchTerms}"; }]; - iconUpdateURL = "https://wiki.nixos.org/favicon.png"; - updateInterval = 24 * 60 * 60 * 1000; + + iconMapObj."16" = "https://wiki.nixos.org/favicon.ico"; definedAliases = [ "@nw" ]; }; @@ -163,6 +163,36 @@ in { }; }; }; + + migrateIconsV12 = { + id = 4; + search = { + force = true; + engines = { + nix-packages = { + name = "Nix Packages"; + + urls = [{ + template = "https://search.nixos.org/packages"; + params = [ + { + name = "type"; + value = "packages"; + } + { + name = "query"; + value = "{searchTerms}"; + } + ]; + }]; + + iconURL = "https://search.nixos.org/favicon.ico"; + iconUpdateURL = "https://search.nixos.org/favicon.ico"; + definedAliases = [ "@np" ]; + }; + }; + }; + }; }; } // { nmt.script = let @@ -212,6 +242,10 @@ in { assertFirefoxSearchContent \ home-files/${cfg.configPath}/migrateIconsV11/search.json.mozlz4 \ ${withName ./expected-migrate-icons-v11.json} + + assertFirefoxSearchContent \ + home-files/${cfg.configPath}/migrateIconsV12/search.json.mozlz4 \ + ${withName ./expected-migrate-icons-v12.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 index c3d5c15f2..d9534b44e 100644 --- a/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v11.json +++ b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v11.json @@ -22,5 +22,5 @@ "metaData": { "useSavedOrder": false }, - "version": 11 + "version": 12 } diff --git a/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v12.json b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v12.json new file mode 100644 index 000000000..bc863e5af --- /dev/null +++ b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons-v12.json @@ -0,0 +1,36 @@ +{ + "engines": [ + { + "_definedAliases": [ + "@np" + ], + "_iconMapObj": { + "16": "https://search.nixos.org/favicon.ico" + }, + "_isAppProvided": false, + "_loadPath": "[home-manager]/programs.@name@.profiles.migrateIconsV12.search.engines.nix-packages", + "_metaData": {}, + "_name": "Nix Packages", + "_urls": [ + { + "params": [ + { + "name": "type", + "value": "packages" + }, + { + "name": "query", + "value": "{searchTerms}" + } + ], + "template": "https://search.nixos.org/packages" + } + ], + "id": "nix-packages" + } + ], + "metaData": { + "useSavedOrder": false + }, + "version": 12 +} diff --git a/tests/modules/programs/firefox/profiles/search/expected-migrate-icons.json b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons.json new file mode 100644 index 000000000..0d03f947c --- /dev/null +++ b/tests/modules/programs/firefox/profiles/search/expected-migrate-icons.json @@ -0,0 +1,54 @@ +{ + "engines": [ + { + "_definedAliases": [ + "@np" + ], + "_iconMapObj": { + "16": "https://search.nixos.org/favicon.ico" + }, + "_isAppProvided": false, + "_loadPath": "[home-manager]/programs.@name@.profiles.migrateIcons.search.engines.nix-packages", + "_metaData": {}, + "_name": "Nix Packages", + "_urls": [ + { + "params": [ + { + "name": "type", + "value": "packages" + }, + { + "name": "query", + "value": "{searchTerms}" + } + ], + "template": "https://search.nixos.org/packages" + } + ], + "id": "nix-packages" + }, + { + "_definedAliases": [ + "@nw" + ], + "_iconMapObj": { + "16": "https://wiki.nixos.org/favicon.ico" + }, + "_isAppProvided": false, + "_loadPath": "[home-manager]/programs.@name@.profiles.migrateIcons.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": 12 +} 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 123eeaf6f..8ec20abe2 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 @@ -4,7 +4,9 @@ "_definedAliases": [ "@np" ], - "_iconURL": "file:///run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg", + "_iconMapObj": { + "16": "file:///run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg" + }, "_isAppProvided": false, "_loadPath": "[home-manager]/programs.librewolf.profiles.migrateSearchV7.search.engines.\"Nix Packages\"", "_metaData": { @@ -32,8 +34,9 @@ "_definedAliases": [ "@nw" ], - "_iconURL": "https://wiki.nixos.org/favicon.ico", - "_iconUpdateURL": "https://wiki.nixos.org/favicon.ico", + "_iconMapObj": { + "16": "https://wiki.nixos.org/favicon.ico" + }, "_isAppProvided": false, "_loadPath": "[home-manager]/programs.librewolf.profiles.migrateSearchV7.search.engines.\"NixOS Wiki\"", "_metaData": { @@ -75,5 +78,5 @@ "privateDefaultEngineIdHash": "@privateHash@", "useSavedOrder": true }, - "version": 11 + "version": 12 } 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 42eea4e71..e752f6e46 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": 11 + "version": 12 } diff --git a/tests/modules/programs/firefox/profiles/search/expected-search.json b/tests/modules/programs/firefox/profiles/search/expected-search.json index d7c0ffece..6177027bb 100644 --- a/tests/modules/programs/firefox/profiles/search/expected-search.json +++ b/tests/modules/programs/firefox/profiles/search/expected-search.json @@ -4,7 +4,9 @@ "_definedAliases": [ "@np" ], - "_iconURL": "file:///run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg", + "_iconMapObj": { + "16": "file:///run/current-system/sw/share/icons/hicolor/scalable/apps/nix-snowflake.svg" + }, "_isAppProvided": false, "_loadPath": "[home-manager]/programs.@name@.profiles.search.search.engines.nix-packages", "_metaData": { @@ -32,18 +34,18 @@ "_definedAliases": [ "@nw" ], - "_iconURL": "https://wiki.nixos.org/favicon.png", - "_iconUpdateURL": "https://wiki.nixos.org/favicon.png", + "_iconMapObj": { + "16": "https://wiki.nixos.org/favicon.ico" + }, "_isAppProvided": false, "_loadPath": "[home-manager]/programs.@name@.profiles.search.search.engines.nixos-wiki", "_metaData": { "order": 2 }, "_name": "NixOS Wiki", - "_updateInterval": 86400000, "_urls": [ { - "template": "https://wiki.nixos.org/index.php?search={searchTerms}" + "template": "https://wiki.nixos.org/w/index.php?search={searchTerms}" } ], "id": "nixos-wiki" @@ -75,5 +77,5 @@ "privateDefaultEngineIdHash": "@privateHash@", "useSavedOrder": true }, - "version": 11 + "version": 12 }