Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 1 | { |
| 2 | config, |
| 3 | lib, |
| 4 | pkgs, |
| 5 | ... |
| 6 | }: let |
| 7 | possibleEngines = [ |
Samuel Shuert | 95554c5 | 2024-02-29 17:04:31 -0500 | [diff] [blame] | 8 | "Amazon" |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 9 | "Arch Wiki" |
| 10 | "Bing" |
Skyler Grey | 5ed8cf4 | 2024-03-01 19:23:15 +0000 | [diff] [blame] | 11 | "Crates.io" |
| 12 | "Docs.rs" |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 13 | "DuckDuckGo" |
| 14 | "eBay" |
| 15 | "Gentoo Wiki" |
| 16 | "GitHub" |
| 17 | "Google" |
| 18 | "Home-Manager Options" |
| 19 | "Kagi" |
| 20 | "MDN" |
| 21 | "NixOS Options" |
| 22 | "NixOS Packages" |
| 23 | "Noogle" |
| 24 | "Wikipedia (en)" |
| 25 | ]; |
| 26 | in { |
| 27 | options.chimera.browser.firefox.search = { |
| 28 | enable = lib.mkEnableOption "Let Chimera control your firefox search engines"; |
| 29 | extensions.enable = lib.mkEnableOption "Install extensions relating to your chosen search engines"; |
| 30 | bookmarks.enable = lib.mkEnableOption "Add bookmarks to quickly jump to your chosen search engines. CAUTION: This option will overwrite (reset) any imperatively-added bookmarks"; |
| 31 | engines = lib.mkOption { |
| 32 | type = lib.types.listOf (lib.types.enum possibleEngines); |
| 33 | description = '' |
| 34 | A list of search engines you want to enable. Any enabled engines will have the following Chimera customizations added: |
| 35 | - They will be added to Firefox (if they are not already a default firefox search engine) |
| 36 | - They will have an alias given[1], you can type "{alias} query" to search query with the engine |
| 37 | - If you have enabled config.chimera.browser.firefox.search.installExtensions, they will have their respective extension |
| 38 | installed (if one exists), e.g. enabling Kagi will install the Kagi extension for private browsing support[2] |
| 39 | - If you have enabled config.chimera.browser.firefox.search.addBookmarks, they will have a shortcut added so you can type |
| 40 | only "{alias}" and go to their homepage. |
| 41 | |
| 42 | The search engines will be ordered according to the order you give them in this list. The first one will be set as your |
| 43 | default search engine. |
| 44 | |
| 45 | 1: |
Samuel Shuert | 95554c5 | 2024-02-29 17:04:31 -0500 | [diff] [blame] | 46 | Amazon -> amazon |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 47 | Arch Wiki -> arch |
| 48 | Bing -> bing |
Skyler Grey | 5ed8cf4 | 2024-03-01 19:23:15 +0000 | [diff] [blame] | 49 | Crates.io -> crates |
| 50 | Docs.rs -> rs |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 51 | DuckDuckGo -> ddg |
| 52 | eBay -> ebay |
| 53 | Gentoo Wiki -> gentoo |
| 54 | GitHub -> gh |
| 55 | Google -> google |
| 56 | Home-Manager Options -> hm |
| 57 | Kagi -> kagi |
| 58 | MDN -> mdn |
| 59 | NixOS Options -> opts |
| 60 | NixOS Packages -> pkgs |
| 61 | Noogle -> lib |
| 62 | Wikipedia (en) -> wiki |
| 63 | 2: |
| 64 | DuckDuckGo installs https://addons.mozilla.org/en-US/firefox/addon/duckduckgo-for-firefox |
| 65 | Kagi installs https://addons.mozilla.org/en-US/firefox/addon/kagi-search-for-firefox/ |
| 66 | ''; |
| 67 | default = [ |
| 68 | "DuckDuckGo" |
| 69 | "MDN" |
| 70 | "NixOS Options" |
| 71 | "NixOS Packages" |
| 72 | "Home-Manager Options" |
| 73 | "Noogle" |
| 74 | "GitHub" |
Skyler Grey | 5ed8cf4 | 2024-03-01 19:23:15 +0000 | [diff] [blame] | 75 | "Docs.rs" |
| 76 | "Crates.io" |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 77 | ]; |
| 78 | example = [ |
| 79 | "Kagi" |
| 80 | "MDN" |
| 81 | "NixOS Options" |
| 82 | "NixOS Packages" |
| 83 | "Home-Manager Options" |
| 84 | "Noogle" |
| 85 | "GitHub" |
Skyler Grey | 5ed8cf4 | 2024-03-01 19:23:15 +0000 | [diff] [blame] | 86 | "Docs.rs" |
| 87 | "Crates.io" |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 88 | "Arch Wiki" |
| 89 | "Gentoo Wiki" |
| 90 | ]; |
| 91 | }; |
| 92 | }; |
| 93 | |
| 94 | config = |
| 95 | let |
| 96 | engineData = { |
Samuel Shuert | 95554c5 | 2024-02-29 17:04:31 -0500 | [diff] [blame] | 97 | "Amazon" = { |
| 98 | homepage = "https://amazon.com"; |
| 99 | metaData.alias = "amazon"; |
| 100 | }; |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 101 | "Arch Wiki" = { |
| 102 | urls = [ { template = "https://wiki.archlinux.org/index.php?search={searchTerms}"; } ]; |
| 103 | iconUpdateURL = "https://wiki.archlinux.org/favicon.ico"; |
| 104 | updateInterval = 24 * 60 * 60 * 1000; |
| 105 | definedAliases = [ "arch" ]; |
| 106 | homepage = "https://wiki.archlinux.org/"; |
| 107 | }; |
| 108 | "Bing" = { |
| 109 | homepage = "https://bing.com"; |
| 110 | metaData.alias = "bing"; |
| 111 | }; |
Skyler Grey | 5ed8cf4 | 2024-03-01 19:23:15 +0000 | [diff] [blame] | 112 | "Crates.io" = { |
| 113 | urls = [ { template = "https://crates.io/search?q={searchTerms}"; } ]; |
| 114 | iconUpdateURL = "https://crates.io/favicon.ico"; |
| 115 | updateInterval = 24 * 60 * 60 * 1000; |
| 116 | definedAliases = [ "crates" ]; |
| 117 | homepage = "https://crates.io"; |
| 118 | }; |
| 119 | "Docs.rs" = { |
| 120 | urls = [ { template = "https://docs.rs/releases/search?query={searchTerms}"; } ]; |
| 121 | iconUpdateURL = "https://docs.rs/favicon.ico"; |
| 122 | updateInterval = 24 * 60 * 60 * 1000; |
| 123 | definedAliases = [ "rs" ]; |
| 124 | homepage = "https://docs.rs"; |
| 125 | }; |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 126 | "DuckDuckGo" = { |
| 127 | homepage = "https://duckduckgo.com"; |
| 128 | metaData.alias = "ddg"; |
| 129 | extraExtensions = [ config.nur.repos.rycee.firefox-addons.duckduckgo-privacy-essentials ]; |
| 130 | }; |
| 131 | "eBay" = { |
| 132 | homepage = "https://ebay.com"; |
| 133 | metaData.alias = "ebay"; |
| 134 | }; |
| 135 | "Gentoo Wiki" = { |
| 136 | urls = [ { template = "https://wiki.gentoo.org/index.php?search={searchTerms}"; } ]; |
| 137 | iconUpdateURL = "https://www.gentoo.org/favicon.ico"; |
| 138 | updateInterval = 24 * 60 * 60 * 1000; |
| 139 | definedAliases = [ "gentoo" ]; |
| 140 | homepage = "https://wiki.gentoo.org"; |
| 141 | }; |
| 142 | "GitHub" = { |
| 143 | urls = [ { template = "https://github.com/search?q={searchTerms}"; } ]; |
| 144 | iconUpdateURL = "https://github.com/favicon.ico"; |
| 145 | updateInterval = 24 * 60 * 60 * 1000; |
| 146 | definedAliases = [ "gh" ]; |
| 147 | homepage = "https://github.com"; |
| 148 | }; |
| 149 | "Google" = { |
| 150 | homepage = "https://google.com"; |
| 151 | metaData.alias = "google"; |
| 152 | }; |
| 153 | "Home-Manager Options" = { |
| 154 | urls = [ |
| 155 | { template = "https://mipmip.github.io/home-manager-option-search/?query={searchTerms}"; } |
| 156 | ]; |
| 157 | iconUpdateURL = "https://mipmip.github.io/home-manager-option-search/images/favicon.png"; |
| 158 | updateInterval = 24 * 60 * 60 * 1000; |
| 159 | definedAliases = [ "hm" ]; |
| 160 | homepage = "https://mipmip.github.io/home-manager-option-search/"; |
| 161 | }; |
| 162 | "Kagi" = { |
| 163 | urls = [ |
| 164 | { template = "https://kagi.com/search?q={searchTerms}"; } |
| 165 | { |
| 166 | template = "https://kagi.com/api/autosuggest?q={searchTerms}"; |
| 167 | type = "application/x-suggestions+json"; |
| 168 | } |
| 169 | ]; |
| 170 | iconUpdateURL = "https://assets.kagi.com/v2/favicon-32x32.png"; |
| 171 | updateInterval = 24 * 60 * 60 * 1000; |
| 172 | homepage = "https://kagi.com"; |
| 173 | definedAliases = [ "kagi" ]; |
| 174 | extraExtensions = [ config.nur.repos.rycee.firefox-addons.kagi-search ]; |
| 175 | }; |
| 176 | "MDN" = { |
| 177 | urls = [ { template = "https://developer.mozilla.org/en-US/search?q={searchTerms}"; } ]; |
| 178 | iconUpdateURL = "https://developer.mozilla.org/favicon.ico"; |
| 179 | updateInterval = 24 * 60 * 60 * 1000; |
| 180 | homepage = "https://developer.mozilla.org"; |
| 181 | definedAliases = [ "mdn" ]; |
| 182 | }; |
| 183 | "NixOS Options" = { |
| 184 | urls = [ { template = "https://search.nixos.org/options?channel=unstable&query={searchTerms}"; } ]; |
| 185 | iconUpdateURL = "https://nixos.org/logo/nix-wiki.png"; |
| 186 | updateInterval = 24 * 60 * 60 * 1000; |
| 187 | homepage = "https://search.nixos.org/options?channel=unstable"; |
| 188 | definedAliases = [ "opts" ]; |
| 189 | }; |
| 190 | "NixOS Packages" = { |
| 191 | urls = [ { template = "https://search.nixos.org/packages?channel=unstable&query={searchTerms}"; } ]; |
| 192 | iconUpdateURL = "https://nixos.org/logo/nix-wiki.png"; |
| 193 | updateInterval = 24 * 60 * 60 * 1000; |
| 194 | homepage = "https://search.nixos.org/packages?channel=unstable"; |
| 195 | definedAliases = [ "pkgs" ]; |
| 196 | }; |
| 197 | "Noogle" = { |
| 198 | urls = [ { template = "https://noogle.dev/q?term={searchTerms}"; } ]; |
| 199 | iconUpdateURL = "https://noogle.dev/favicon.png"; |
| 200 | updateInterval = 24 * 60 * 60 * 1000; |
| 201 | homepage = "https://noogle.dev"; |
| 202 | definedAliases = [ "lib" ]; |
| 203 | }; |
| 204 | "Wikipedia (en)" = { |
| 205 | homepage = "https://en.wikipedia.org"; |
| 206 | metaData.alias = "wiki"; |
| 207 | }; |
| 208 | }; |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 209 | calculated = lib.pipe engineData [ |
Skyler Grey | 416d9d0 | 2024-02-29 17:08:30 -0500 | [diff] [blame] | 210 | (lib.filterAttrs (engine: _: builtins.elem engine config.chimera.browser.firefox.search.engines)) |
Skyler Grey | cd3d38b | 2024-02-25 15:18:32 +0000 | [diff] [blame] | 211 | (builtins.mapAttrs ( |
| 212 | name: value: { |
| 213 | engines.${name} = |
| 214 | lib.filterAttrs |
| 215 | ( |
| 216 | option: _: |
| 217 | !(builtins.elem option [ |
| 218 | "homepage" |
| 219 | "extraExtensions" |
| 220 | ]) |
| 221 | ) |
| 222 | value; |
| 223 | extensions = if builtins.hasAttr "extraExtensions" value then value.extraExtensions else [ ]; |
| 224 | bookmarks = |
| 225 | if builtins.hasAttr "homepage" value then |
| 226 | [ |
| 227 | { |
| 228 | inherit name; |
| 229 | keyword = if builtins.hasAttr "definedAliases" value |
| 230 | then builtins.elemAt value.definedAliases 0 |
| 231 | else value.metaData.alias; |
| 232 | url = value.homepage; |
| 233 | } |
| 234 | ] |
| 235 | else |
| 236 | [ ]; |
| 237 | } |
| 238 | )) |
| 239 | builtins.attrValues |
| 240 | (lib.zipAttrsWithNames ["engines" "extensions" "bookmarks"] (name: values: if name == "engines" |
| 241 | then lib.attrsets.mergeAttrsList values |
| 242 | else builtins.concatLists values)) |
| 243 | ]; |
| 244 | removedEngines = lib.pipe possibleEngines [ |
| 245 | (builtins.filter (engine: !(builtins.elem engine config.chimera.browser.firefox.search.engines))) |
| 246 | (map (engine: { |
| 247 | name = engine; |
| 248 | value.metaData.hidden = true; |
| 249 | })) |
| 250 | builtins.listToAttrs |
| 251 | ]; # We need to hide all the engines that we aren't selecting, because engines that we unset are not removed |
| 252 | in |
| 253 | lib.mkIf config.chimera.browser.firefox.search.enable { |
| 254 | programs.firefox.profiles.chimera = { |
| 255 | search = { |
| 256 | engines = calculated.engines // removedEngines; |
| 257 | order = config.chimera.browser.firefox.search.engines; |
| 258 | default = lib.mkIf (builtins.length config.chimera.browser.firefox.search.engines > 0) ( |
| 259 | builtins.elemAt config.chimera.browser.firefox.search.engines 0 |
| 260 | ); |
| 261 | force = true; |
| 262 | }; |
| 263 | extensions = lib.mkIf config.chimera.browser.firefox.search.extensions.enable calculated.extensions; |
| 264 | bookmarks = lib.mkIf config.chimera.browser.firefox.search.bookmarks.enable calculated.bookmarks; |
| 265 | }; |
| 266 | }; |
| 267 | } |