From c52c7f314ccadcc2fcd91e28c8fd1b88f6d5ce0c Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 18 Oct 2024 17:07:46 +0200 Subject: refactor(modules): Move all system modules to `by-name` From now on all modules should be added to the new `by-name` directory. This should help remove the (superficial and utterly useless) distinction between `home-manager` and `NixOS` modules. --- .../conf/firefox/config/bookmarks/default.nix | 31 ++++ .../conf/firefox/config/bookmarks/lib.nix | 49 +++++ .../conf/firefox/config/chrome/userChrome.css | 41 +++++ .../conf/firefox/config/extensions/extensions.json | 50 +++++ .../extensions/native_messaging_hosts/default.nix | 15 ++ .../conf/firefox/config/policies/default.nix | 146 +++++++++++++++ .../conf/firefox/config/prefs/default.nix | 21 +++ .../conf/firefox/config/prefs/override.js | 202 +++++++++++++++++++++ .../conf/firefox/config/search/engines/default.nix | 84 +++++++++ .../config/search/engines/logos/arch_linux.svg | 1 + .../firefox/config/search/engines/logos/brave.svg | 25 +++ .../config/search/engines/logos/google_scholar.ico | Bin 0 -> 3871 bytes .../config/search/engines/logos/rust_std.svg | 47 +++++ .../config/search/engines/logos/rust_tokio.png | Bin 0 -> 3551 bytes .../config/search/engines/logos/wikipedia.svg | 1 + modules/home.legacy/conf/firefox/default.nix | 134 ++++++++++++++ modules/home.legacy/conf/firefox/package.nix | 30 +++ .../home.legacy/conf/firefox/scripts/default.nix | 29 +++ .../conf/firefox/scripts/extract_cookies.sh | 77 ++++++++ .../conf/firefox/scripts/unzip_mozlz4.py | 44 +++++ .../conf/firefox/scripts/update_extensions.sh | 18 ++ 21 files changed, 1045 insertions(+) create mode 100644 modules/home.legacy/conf/firefox/config/bookmarks/default.nix create mode 100644 modules/home.legacy/conf/firefox/config/bookmarks/lib.nix create mode 100644 modules/home.legacy/conf/firefox/config/chrome/userChrome.css create mode 100644 modules/home.legacy/conf/firefox/config/extensions/extensions.json create mode 100644 modules/home.legacy/conf/firefox/config/extensions/native_messaging_hosts/default.nix create mode 100644 modules/home.legacy/conf/firefox/config/policies/default.nix create mode 100644 modules/home.legacy/conf/firefox/config/prefs/default.nix create mode 100644 modules/home.legacy/conf/firefox/config/prefs/override.js create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/default.nix create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/logos/arch_linux.svg create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/logos/brave.svg create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/logos/google_scholar.ico create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/logos/rust_std.svg create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/logos/rust_tokio.png create mode 100644 modules/home.legacy/conf/firefox/config/search/engines/logos/wikipedia.svg create mode 100644 modules/home.legacy/conf/firefox/default.nix create mode 100644 modules/home.legacy/conf/firefox/package.nix create mode 100644 modules/home.legacy/conf/firefox/scripts/default.nix create mode 100755 modules/home.legacy/conf/firefox/scripts/extract_cookies.sh create mode 100755 modules/home.legacy/conf/firefox/scripts/unzip_mozlz4.py create mode 100755 modules/home.legacy/conf/firefox/scripts/update_extensions.sh (limited to 'modules/home.legacy/conf/firefox') diff --git a/modules/home.legacy/conf/firefox/config/bookmarks/default.nix b/modules/home.legacy/conf/firefox/config/bookmarks/default.nix new file mode 100644 index 00000000..c612bf4d --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/bookmarks/default.nix @@ -0,0 +1,31 @@ +{ + lib, + pkgs, + ... +}: let + bookmarks = [ + { + name = "Feed - Piped"; + url = "https://piped.video/feed"; + } + + { + name = "DeepL Translate"; + url = "https://www.deepl.com/translator"; + } + + { + name = "Nix lib"; + url = "https://teu5us.github.io/nix-lib.html"; + } + + { + name = "Nixpkgs manual"; + url = "https://ryantm.github.io/nixpkgs/"; + } + ]; + + mkBookmarksFile = (import ./lib.nix) {inherit lib pkgs;}; + bookmarks_file = mkBookmarksFile bookmarks; +in + bookmarks_file diff --git a/modules/home.legacy/conf/firefox/config/bookmarks/lib.nix b/modules/home.legacy/conf/firefox/config/bookmarks/lib.nix new file mode 100644 index 00000000..d1d89dd2 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/bookmarks/lib.nix @@ -0,0 +1,49 @@ +{ + lib, + pkgs, +}: bookmarks: let + indent = level: + lib.concatStringsSep "" (map (lib.const " ") (lib.range 1 level)); + + bookmarkToHTML = indentLevel: bookmark: '' + ${indent indentLevel}
${lib.escapeXML bookmark.name}''; + + directoryToHTML = indentLevel: directory: '' + ${indent indentLevel}
${ + if directory.toolbar + then ''

Bookmarks Toolbar'' + else "

${lib.escapeXML directory.name}" + }

+ ${indent indentLevel}

+ ${allItemsToHTML (indentLevel + 1) directory.bookmarks} + ${indent indentLevel}

''; + + itemToHTMLOrRecurse = indentLevel: item: + if item ? "url" + then bookmarkToHTML indentLevel item + else directoryToHTML indentLevel item; + + allItemsToHTML = indentLevel: bookmarks: + lib.concatStringsSep "\n" + (map (itemToHTMLOrRecurse indentLevel) bookmarks); + + bookmarkEntries = allItemsToHTML 1 bookmarks; +in + pkgs.writeText "firefox-bookmarks.html" '' + + + + Bookmarks +

Bookmarks Menu

+ +

+

Bookmarks Toolbar

+

+ ${bookmarkEntries} +

+

+ '' diff --git a/modules/home.legacy/conf/firefox/config/chrome/userChrome.css b/modules/home.legacy/conf/firefox/config/chrome/userChrome.css new file mode 100644 index 00000000..0b3aff77 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/chrome/userChrome.css @@ -0,0 +1,41 @@ +/* thickness of tab when you have too many open tabs */ +.tabbrowser-tab:not([pinned="true"]) { + min-width: 10px !important; + min-height: 10px !important; +} + +/* tab height +#TabsToolbar .tabbrowser-tabs { +min-height: 10px !important; +} +*/ + +/* +.tabbrowser-tab {min-width: 016px !important;} +.tabbrowser-tab {clip-width: 016px !important;} +*/ + +/* the + button that opens new tabs */ +#TabsToolbar .tabs-newtab-button { + margin-left: 10px !important; + height: Auto !important; +} + +#main-window[privatebrowsingmode="temporary"] #navigator-toolbox { + background-color: #c40944 !important; +} + +/* close button inside a tab */ +.tab-close-button * { + width: 10px !important; + height: 10px !important; +} + +/* bookmark toolbar */ +#personal-bookmarks .bookmark-item > .toolbarbutton-text { + font-size: 10pt !important; +} +#personal-bookmarks .bookmark-item > .toolbarbutton-icon { + height: 12px !important; + width: 12px !important; +} diff --git a/modules/home.legacy/conf/firefox/config/extensions/extensions.json b/modules/home.legacy/conf/firefox/config/extensions/extensions.json new file mode 100644 index 00000000..be05e957 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/extensions/extensions.json @@ -0,0 +1,50 @@ +{ + "darkreader": { + "addonId": "addon@darkreader.org", + "default_area": "navbar", + "pname": "darkreader", + "sha256": "sha256:251c4e7d0a30c0cab006803600e59ab92dcc0c606429740d42677846d4c9ccd6", + "url": "https://addons.mozilla.org/firefox/downloads/file/4359254/darkreader-4.9.94.xpi", + "version": "4.9.94" + }, + "keepassxc-browser": { + "addonId": "keepassxc-browser@keepassxc.org", + "default_area": "navbar", + "pname": "keepassxc-browser", + "sha256": "sha256:a330fa4fc659f04f835802bb0c5df0b9025adced995112cad19d4849a5f1957d", + "url": "https://addons.mozilla.org/firefox/downloads/file/4342010/keepassxc_browser-1.9.3.xpi", + "version": "1.9.3" + }, + "torproject-snowflake": { + "addonId": "{b11bea1f-a888-4332-8d8a-cec2be7d24b9}", + "default_area": "navbar", + "pname": "torproject-snowflake", + "sha256": "sha256:a6b11d5250e6c30c9a0d4b1caaedc446a7fb31bb78088fa14554fdd1e3741cb3", + "url": "https://addons.mozilla.org/firefox/downloads/file/4310769/torproject_snowflake-0.8.4.xpi", + "version": "0.8.4" + }, + "tridactyl-vim": { + "addonId": "tridactyl.vim@cmcaine.co.uk", + "default_area": "menupanel", + "pname": "tridactyl-vim", + "sha256": "sha256:ab63fe1554471c280f234409393172fc58e1bb2ca527f4329d983b028073e19c", + "url": "https://addons.mozilla.org/firefox/downloads/file/4261352/tridactyl_vim-1.24.1.xpi", + "version": "1.24.1" + }, + "ublock-origin": { + "addonId": "uBlock0@raymondhill.net", + "default_area": "menupanel", + "pname": "ublock-origin", + "sha256": "sha256:e2cda9b2a1b0a7f6e5ef0da9f87f28df52f8560587ba2e51a3003121cfb81600", + "url": "https://addons.mozilla.org/firefox/downloads/file/4359936/ublock_origin-1.60.0.xpi", + "version": "1.60.0" + }, + "vhack-libredirect": { + "addonId": "vhack-libredirect@addons.vhack.eu", + "default_area": "navbar", + "pname": "vhack-libredirect", + "sha256": "sha256:2cb6befac6f414e0dd79a11db8905a0d988b98633b74afbe52ffe8006da841f5", + "url": "https://addons.mozilla.org/firefox/downloads/file/4351448/vhack_libredirect-2.9.1.xpi", + "version": "2.9.1" + } +} diff --git a/modules/home.legacy/conf/firefox/config/extensions/native_messaging_hosts/default.nix b/modules/home.legacy/conf/firefox/config/extensions/native_messaging_hosts/default.nix new file mode 100644 index 00000000..9aaa1682 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/extensions/native_messaging_hosts/default.nix @@ -0,0 +1,15 @@ +{pkgs, ...}: +/* +++ lib.optional (cfg.enableBrowserpass or false) (lib.getBin browserpass) +++ lib.optional (cfg.enableBukubrow or false) bukubrow +++ lib.optional (cfg.enableTridactylNative or false) tridactyl-native +++ lib.optional (cfg.enableGnomeExtensions or false) gnome-browser-connector +++ lib.optional (cfg.enableUgetIntegrator or false) uget-integrator +++ lib.optional (cfg.enablePlasmaBrowserIntegration or false) plasma5Packages.plasma-browser-integration +++ lib.optional (cfg.enableFXCastBridge or false) fx-cast-bridge +++ lib.optional (cfg.enableKeePassXC or false) keepassxc +*/ +with pkgs; [ + tridactyl-native + keepassxc +] diff --git a/modules/home.legacy/conf/firefox/config/policies/default.nix b/modules/home.legacy/conf/firefox/config/policies/default.nix new file mode 100644 index 00000000..02c740f6 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/policies/default.nix @@ -0,0 +1,146 @@ +{ + config, + extensions, + ... +}: let + locals = [ + "en-CA" + "de" + "sv-SE" + ]; + mkAllowedExtension = extension: { + name = extension.addonId; + value = { + installation_mode = "normal_installed"; + updates_disabled = true; + inherit (extension) default_area; + install_url = "file://${builtins.fetchurl { + inherit + (extension) + url + sha256 + ; + }}"; + }; + }; + allowedExtensions = + builtins.listToAttrs + (builtins.map mkAllowedExtension (builtins.attrValues + extensions)); + + mkBlockedExtension = id: { + name = id; + value = { + install_mode = "blocked"; + }; + }; + blockedExtensions = builtins.listToAttrs (builtins.map mkBlockedExtension [ + # these are the default search engines + "addons-search-detection@mozilla.com" + "amazon@search.mozilla.org" + "bing@search.mozilla.org" + "ddg@search.mozilla.org" + "google@search.mozilla.org" + "wikipedia@search.mozilla.org" + ]); + + language_packs = builtins.listToAttrs (builtins.map + ( + lang: { + name = "langpack-${lang}@firefox.mozilla.org"; + value = { + installation_mode = "normal_installed"; + updates_disabled = true; + install_url = "https://releases.mozilla.org/pub/firefox/releases/${config.soispha.firefox.package_version}/linux-x86_64/xpi/${lang}.xpi"; + }; + } + ) + locals); +in { + # NOTE: See https://mozilla.github.io/policy-templates for documentation <2023-10-21> + policies = { + # NixOS manages this already + DisableAppUpdate = true; + + DisableFirefoxAccounts = true; + DisableFirefoxScreenshots = true; + + # KeepassXC does this for me + DisableMasterPasswordCreation = true; + + # I use a self-hosted services for that + DisablePocket = true; + + # I don't want to lose my data + DisableProfileRefresh = true; + + DisableDeveloperTools = false; + + DisplayBookmarksToolbar = "newtab"; + DisplayMenuBar = "default-off"; + + DNSOverHTTPS = { + Enabled = true; + Locked = false; + }; + # The concept of a "default browser" does not apply to my NixOS config + DontCheckDefaultBrowser = true; + + EnableTrackingProtection = { + Value = true; + Locked = false; + Cryptomining = true; + Fingerprinting = true; + EmailTracking = true; + }; + + EncryptedMediaExtensions = { + # I want a _free_ config (and I can always just run another browser) + Enabled = false; + Locked = true; + }; + + ExtensionSettings = + { + "*" = { + # Blocking the extension install here, also blocks the 'about:debugging' page + + # blocked_install_message = '' + # You can't install a extension manually, + # please specify it in your NixOS configuration + # ''; + installation_mode = "allowed"; + }; + } + // allowedExtensions + // blockedExtensions + // language_packs; + + ExtensionUpdate = false; + + # TODO: Add handlers for the default file types <2023-10-21> + # Handlers = { + # }; + + HardwareAcceleration = true; + + # Blocking the extension install here, also blocks the 'about:debugging' page + # InstallAddonsPermission = { + # Allowed = []; + # Default = false; + # }; + + # KeepassXC and such things + OfferToSaveLogins = false; + PasswordManagerEnabled = false; + + PDFjs = { + Enabled = true; + # Don't honor documents right to be un-copy-able + EnablePermissions = false; + }; + + SearchBar = "unified"; + RequestedLocales = locals; + }; +} diff --git a/modules/home.legacy/conf/firefox/config/prefs/default.nix b/modules/home.legacy/conf/firefox/config/prefs/default.nix new file mode 100644 index 00000000..80c6d274 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/prefs/default.nix @@ -0,0 +1,21 @@ +{ + pkgs, + config, + user_js, + bookmarks, + ... +}: let + user_js_override = pkgs.writeText "user.override.js" (builtins.readFile ./override.js); +in + pkgs.runCommand "user.js" {} '' + mkdir $out; + cat "${user_js}/user.js" > $out/user.js; + cat "${user_js_override}" >> $out/user.js; + + cat << EOF >> $out/user.js; + // My bookmarks + user_pref("browser.bookmarks.file", "${toString bookmarks}"); + user_pref("browser.startup.homepage", "file:///home/dt/home.html"); // 0103 // TODO: add this from a flake + user_pref("browser.download.dir", "${config.xdg.userDirs.download}"); + EOF + '' diff --git a/modules/home.legacy/conf/firefox/config/prefs/override.js b/modules/home.legacy/conf/firefox/config/prefs/override.js new file mode 100644 index 00000000..bf874b33 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/prefs/override.js @@ -0,0 +1,202 @@ +/* + 0100: STARTUP + 0200: GEOLOCATION / LANGUAGE / LOCALE + 0300: QUIETER FOX + 0400: SAFE BROWSING + 0600: BLOCK IMPLICIT OUTBOUND + 0700: DNS / DoH / PROXY / SOCKS / IPv6 + 0800: LOCATION BAR / SEARCH BAR / SUGGESTIONS / HISTORY / FORMS + 0900: PASSWORDS + 1000: DISK AVOIDANCE + 1200: HTTPS (SSL/TLS / OCSP / CERTS / HPKP) + 1400: FONTS + 1600: HEADERS / REFERERS + 1700: CONTAINERS + 2000: PLUGINS / MEDIA / WEBRTC + 2400: DOM (DOCUMENT OBJECT MODEL) + 2600: MISCELLANEOUS + 2700: ETP (ENHANCED TRACKING PROTECTION) + 2800: SHUTDOWN & SANITIZING + 4500: RFP (RESIST FINGERPRINTING) + 5000: OPTIONAL OPSEC + 5500: OPTIONAL HARDENING + 6000: DON'T TOUCH + 7000: DON'T BOTHER + 8000: DON'T BOTHER: FINGERPRINTING + 9000: NON-PROJECT RELATED + 9999: DEPRECATED / REMOVED / LEGACY / RENAMED +*/ + + +// restore session +user_pref("browser.startup.page", 3); // 0102 + +user_pref("browser.newtabpage.enabled", true); // 0104 + +// disable the geoservice, TODO: don't know if I want this +//user_pref("geo.provider.use_geoclue", false); // 0202 + +// TODO: is this something useful? +user_pref("datareporting.policy.dataSubmissionEnabled", true); // 0330 + +// enable health reports +user_pref("datareporting.healthreport.uploadEnabled", true); // 0331 + +// Do I want to opt-out? +user_pref("toolkit.telemetry.coverage.opt-out", false); // 0333 + +// enables studies +user_pref("app.shield.optoutstudies.enabled", true); // 0340 + +// I guess that browsing protection is useful +user_pref("browser.safebrowsing.downloads.remote.enabled", true); // 0403 + +// TODO: does this (-> set to false) make things slower? +user_pref("network.prefetch-next", true); // 0601 + +// enable ipv6 because the rest of the system uses it +user_pref("network.dns.disableIPv6", false); // 0701 + +// TRR only +user_pref("network.trr.mode", 3); // 0710 + +// I trust my search engine +user_pref("keyword.enabled", true); // 801 +user_pref("browser.search.suggest.enabled", true); // 0804 +user_pref("browser.urlbar.suggest.searches", true); // 0804 +// TODO: no idea what this does, enabling it +user_pref("browser.urlbar.showSearchTerms.enabled", true); // 9004 + +// prefetch urls, if the get auto completed +user_pref("browser.urlbar.speculativeConnect.enabled", true); // 0805 + +// Disable autoScrolling (clicking with the mouse wheel) +user_pref("general.autoScroll", false); + +// add new tabs after the current one +user_pref("browser.tabs.insertAfterCurrent", true); + +// TODO: I might want to enable this +//user_pref("browser.urlbar.suggest.quicksuggest.nonsponsored", false); // 0807 + +// TODO: enable form and search history? +//user_pref("browser.formfill.enable", false); // 0810 + +// disk cache should help performance +user_pref("browser.cache.disk.enable", true); // 1001 + +// store extra session data (form content, cookies and POST data) 0: everywhere +user_pref("browser.sessionstore.privacy_level", 0); // 1003 + +// Disable unsafe passive content (images) on https sites +user_pref("security.mixed_content.block_display_content", true); // 1241 + +// Disable the eme banner +user_pref("browser.eme.ui.enabled", false); // 2022 + +// Don't delete my precious temp files +user_pref("browser.helperApps.deleteTempFileOnExit", false); // 2603 + +// Download to the download dir +user_pref("browser.download.useDownloadDir", true); // 2651 + +// Open the download panel +user_pref("browser.download.alwaysOpenPanel", true); // 2652 + +// Block after custom ruleset +user_pref("browser.contentblocking.category", "custom"); // 2701 + +// set the custom settings // 7016 +user_pref("network.cookie.cookieBehavior", 1); +user_pref("network.http.referer.disallowCrossSiteRelaxingDefault", true); +user_pref("network.http.referer.disallowCrossSiteRelaxingDefault.top_navigation", true); +user_pref("privacy.partition.network_state.ocsp_cache", true); +user_pref("privacy.query_stripping.enabled", true); +user_pref("privacy.trackingprotection.enabled", true); +user_pref("privacy.trackingprotection.socialtracking.enabled", true); +user_pref("privacy.trackingprotection.cryptomining.enabled", true); +user_pref("privacy.trackingprotection.fingerprinting.enabled", true); + + +// I might want to change that, when it hinders session restore +//user_pref("privacy.partition.always_partition_third_party_non_cookie_storage.exempt_sessionstorage", false); // 2720 + +// I like my history very much! +user_pref("privacy.sanitize.sanitizeOnShutdown", false); // 2810 + +// The downsides (light theme + potential breakages): +//user_pref("privacy.resistFingerprinting", true); // 4501 +user_pref("privacy.resistFingerprinting.letterboxing", false); // 4504 + +// I would like to keep my gl, even in the web +user_pref("webgl.disabled", false); // 4520 + +// I like my service workers and am using a service using them. +user_pref("dom.serviceWorkers.enabled", true); // 7017 + +// I've got a password manager already +user_pref("signon.rememberSignons", false); // 5003 + +// Do not track header +user_pref("privacy.donottrackheader.enabled", true); // 7015 + +// Allow my custom css +user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true); + +// might improve performance TODO: +user_pref("gfx.webrender.all", true); + +// disable updates (pretty pointless with nix) +user_pref("extensions.update.autoUpdateDefault", false); +user_pref("extensions.update.enabled", false); +user_pref("app.update.channel", "default"); + +user_pref("browser.ctrlTab.recentlyUsedOrder", false); + +user_pref("browser.download.useDownloadDir", true); +user_pref("browser.download.folderList", 2); // TODO: +user_pref("browser.download.viewableInternally.typeWasRegistered.svg", true); +user_pref("browser.download.viewableInternally.typeWasRegistered.webp", true); +user_pref("browser.download.viewableInternally.typeWasRegistered.xml", true); + +// TODO: what does this do? +user_pref("browser.search.widget.inNavBar", true); + +user_pref("browser.shell.checkDefaultBrowser", false); +user_pref("browser.tabs.loadInBackground", true); +user_pref("browser.urlbar.placeholderName", "Brave"); + +// Set the tabs and bookmarks +user_pref("browser.tabs.inTitlebar", 1); +user_pref("browser.toolbars.bookmarks.visibility", "always"); +user_pref("browser.places.importBookmarksHTML", true); + +// Theme +user_pref("extensions.activeThemeID", "firefox-alpenglow@mozilla.org"); +user_pref("extensions.extensions.activeThemeID", "firefox-alpenglow@mozilla.org"); + +// highlight all entries when searching +user_pref("findbar.highlightAll", true); + +// Set the default position for the developer toolbox +user_pref("devtools,toolbox.host", "right"); +user_pref("devtools,toolsidebar-width.inspector", 700); + +// Don't bother me with translations +user_pref("browser.translations.automaticallyPopup", true); +user_pref("browser.translations.neverTranslateLanguages", "de"); + +// Put all downloads into the downloads directory +user_pref("browser.download.start_downloads_in_tmp_dir", false); + +// TODO: +//user_pref("extensions.webcompat.enable_picture_in_picture_overrides", true); +//user_pref("extensions.webcompat.enable_shims", true); +//user_pref("extensions.webcompat.perform_injections", true); +//user_pref("extensions.webcompat.perform_ua_overrides", true); + +// onlykey / copied from a yubikey config +//user_pref("security.webauth.u2f", true); +//user_pref("security.webauth.webauthn", true); +//user_pref("security.webauth.webauthn_enable_softtoken", true); +//user_pref("security.webauth.webauthn_enable_usbtoken", true); diff --git a/modules/home.legacy/conf/firefox/config/search/engines/default.nix b/modules/home.legacy/conf/firefox/config/search/engines/default.nix new file mode 100644 index 00000000..a47c77df --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/search/engines/default.nix @@ -0,0 +1,84 @@ +{pkgs, ...}: { + # DEFAULT + "Brave Search" = { + urls = [{template = "https://search.brave.com/search?q={searchTerms}";}]; + icon = ./logos/brave.svg; + definedAliases = ["@bs"]; + }; + + # NIX + "Nix Packages" = { + urls = [{template = "https://search.nixos.org/packages?type=packages&query={searchTerms}";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@np"]; + }; + + "NixOS Options" = { + urls = [{template = "https://search.nixos.org/options?type=options&query={searchTerms}";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@no"]; + }; + "HomeManager Options" = { + urls = [{template = "https://home-manager-options.extranix.com/?query={searchTerms}&release=master";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@nh"]; + }; + + "Nixpkgs issues" = { + urls = [{template = "https://github.com/NixOS/nixpkgs/issues?q=is%3Aissue+is%3Aopen+{searchTerms}";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@ni"]; + }; + "Nixpkgs pull requests" = { + urls = [{template = "https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+is%3Aopen+{searchTerms}";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@nr"]; + }; + + "Nixpkgs pull requests tracker" = { + urls = [{template = "https://nixpk.gs/pr-tracker.html?pr={searchTerms}";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@nt"]; + }; + "NixOS Wiki" = { + urls = [{template = "https://wiki.nixos.org/w/index.php?search={searchTerms}";}]; + icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg"; + definedAliases = ["@nw"]; + }; + + # RUST + "Rust std" = { + urls = [{template = "https://doc.rust-lang.org/std/?search={searchTerms}";}]; + icon = ./logos/rust_std.svg; + definedAliases = ["@rs"]; + }; + "Rust tokio" = { + urls = [{template = "https://docs.rs/tokio/latest/tokio/index.html?search={searchTerms}";}]; + icon = ./logos/rust_tokio.png; + definedAliases = ["@rt"]; + }; + + # OTHER + "Google Scholar" = { + urls = [{template = "https://scholar.google.com/scholar?hl=en&q={searchTerms}";}]; + icon = ./logos/google_scholar.ico; + definedAliases = ["@gs"]; + }; + "Wikipedia" = { + urls = [{template = "https://en.wikipedia.org/wiki/{searchTerms}";}]; + icon = ./logos/wikipedia.svg; + definedAliases = ["@wp"]; + }; + "Arch Wiki" = { + urls = [{template = "https://wiki.archlinux.org/index.php?search={searchTerms}";}]; + icon = ./logos/arch_linux.svg; + definedAliases = ["@aw"]; + }; + + "Wikipedia (en)".metaData.hidden = true; + "DuckDuckGo".metaData.hidden = true; + "Bing".metaData.hidden = true; + "Google".metaData.hidden = true; + "Amazon.de".metaData.hidden = true; + "eBay".metaData.hidden = true; +} diff --git a/modules/home.legacy/conf/firefox/config/search/engines/logos/arch_linux.svg b/modules/home.legacy/conf/firefox/config/search/engines/logos/arch_linux.svg new file mode 100644 index 00000000..949b5c5f --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/search/engines/logos/arch_linux.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/home.legacy/conf/firefox/config/search/engines/logos/brave.svg b/modules/home.legacy/conf/firefox/config/search/engines/logos/brave.svg new file mode 100644 index 00000000..09dd2e42 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/search/engines/logos/brave.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/home.legacy/conf/firefox/config/search/engines/logos/google_scholar.ico b/modules/home.legacy/conf/firefox/config/search/engines/logos/google_scholar.ico new file mode 100644 index 00000000..85d0c664 Binary files /dev/null and b/modules/home.legacy/conf/firefox/config/search/engines/logos/google_scholar.ico differ diff --git a/modules/home.legacy/conf/firefox/config/search/engines/logos/rust_std.svg b/modules/home.legacy/conf/firefox/config/search/engines/logos/rust_std.svg new file mode 100644 index 00000000..0091b5a8 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/search/engines/logos/rust_std.svg @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/home.legacy/conf/firefox/config/search/engines/logos/rust_tokio.png b/modules/home.legacy/conf/firefox/config/search/engines/logos/rust_tokio.png new file mode 100644 index 00000000..f1de55ff Binary files /dev/null and b/modules/home.legacy/conf/firefox/config/search/engines/logos/rust_tokio.png differ diff --git a/modules/home.legacy/conf/firefox/config/search/engines/logos/wikipedia.svg b/modules/home.legacy/conf/firefox/config/search/engines/logos/wikipedia.svg new file mode 100644 index 00000000..dc32f984 --- /dev/null +++ b/modules/home.legacy/conf/firefox/config/search/engines/logos/wikipedia.svg @@ -0,0 +1 @@ +]>Wikipedia logo version 2 \ No newline at end of file diff --git a/modules/home.legacy/conf/firefox/default.nix b/modules/home.legacy/conf/firefox/default.nix new file mode 100644 index 00000000..f2ccfc99 --- /dev/null +++ b/modules/home.legacy/conf/firefox/default.nix @@ -0,0 +1,134 @@ +{ + config, + pkgs, + lib, + user_js, + ... +}: let + extensions = + builtins.fromJSON (builtins.readFile ./config/extensions/extensions.json); + + userChrome = builtins.readFile ./config/chrome/userChrome.css; + bookmarks = (import ./config/bookmarks/default.nix) { + inherit + pkgs + lib + ; + }; + engines = (import ./config/search/engines) {inherit pkgs;}; + + native_messaging_hosts = (import ./config/extensions/native_messaging_hosts/default.nix) {inherit pkgs;}; + + policies = (import ./config/policies) {inherit config extensions;}; + + search = { + default = "Brave Search"; + privateDefault = "Brave Search"; + force = true; + order = [ + # DEFAULT + "Brave Search" + + # NIX + "Nix Packages" + "Nix Options" + "Nixpkgs issues" + "Homemanager Options" + "NixOS Wiki" + "Nixpkgs Pull Request Tracker" + + # RUST + "Rust std" + "Rust tokio" + + # OTHER + "Google Scholar" + "Wikipedia" + "Arch Wiki" + ]; + + inherit engines; + }; + + prefConfig = builtins.readFile "${ + (import ./config/prefs) {inherit pkgs lib config bookmarks user_js;} + }/user.js"; + + # Package {{{ + package = import ./package.nix { + inherit config lib pkgs; + extraPolicies = policies; + extraNativeMessagingHosts = native_messaging_hosts; + }; + # }}} + + # Profiles {{{ + profiles = { + "default" = { + inherit search userChrome; + isDefault = true; + id = 0; + name = "default"; + extraConfig = prefConfig; + }; + }; + + taskwarriorProfiles = import ../taskwarrior/firefox { + inherit + config + lib + # options + + prefConfig + search + userChrome + ; + profile_size = builtins.length (builtins.attrNames profiles); + }; + # }}} +in { + options.soispha.firefox = { + package = lib.mkOption { + type = lib.types.package; + default = pkgs.firefox; + description = "Firefox package to use."; + defaultText = lib.literalExpression "pkgs.firefox"; + relatedPackages = [ + "firefox" + "firefox-beta-bin" + "firefox-bin" + "firefox-devedition-bin" + "firefox-esr" + ]; + }; + package_version = lib.mkOption { + type = lib.types.str; + default = pkgs.firefox.version; + description = "Firefox version to use"; + }; + }; + + config = { + soispha.firefox.package = package; + soispha.firefox.package_version = pkgs.firefox.version; + home.sessionVariables = { + # improve touch input & make scrolling smother + MOZ_USE_XINPUT2 = "1"; + + # improve wayland support + MOZ_ENABLE_WAYLAND = 1; + + # tell gtk to use portals + GTK_USE_PORTAL = 1; + + BROWSER = "firefox"; + }; + programs.firefox = { + enable = true; + inherit (config.soispha.firefox) package; + profiles = + profiles + // taskwarriorProfiles; + }; + }; +} diff --git a/modules/home.legacy/conf/firefox/package.nix b/modules/home.legacy/conf/firefox/package.nix new file mode 100644 index 00000000..f7e4319b --- /dev/null +++ b/modules/home.legacy/conf/firefox/package.nix @@ -0,0 +1,30 @@ +# taken from the NixOS Firefox module: https://github.com/NixOS/nixpkgs/blob/7c9cc5a6e5d38010801741ac830a3f8fd667a7a0/nixos/modules/programs/firefox.nix +{ + config, + lib, + pkgs, + # options + autoConfig ? "", + extraNativeMessagingHosts ? [], + wrapperConfig ? {}, + extraPolicies ? {}, + base_package ? pkgs.firefox, +}: let + pkg = base_package.override (old: { + extraPrefsFiles = + (old.extraPrefsFiles or []) + ++ [ + (pkgs.writeText "autoConfig.js" autoConfig) + ]; + nativeMessagingHosts = old.nativeMessagingHosts or [] ++ extraNativeMessagingHosts; + cfg = (old.cfg or {}) // wrapperConfig; + extraPoliciesFiles = + (old.extraPoliciesFiles or []) + ++ [ + ( + pkgs.writeText "policies.json" (builtins.toJSON extraPolicies) + ) + ]; + }); +in + pkg diff --git a/modules/home.legacy/conf/firefox/scripts/default.nix b/modules/home.legacy/conf/firefox/scripts/default.nix new file mode 100644 index 00000000..1127662b --- /dev/null +++ b/modules/home.legacy/conf/firefox/scripts/default.nix @@ -0,0 +1,29 @@ +{ + pkgs, + sysLib, + ... +}: let + unzip_mozlz4 = pkgs.stdenv.mkDerivation { + name = "unzip_mozlz4"; + propagatedBuildInputs = [ + (pkgs.python3.withPackages (pythonPackages: + with pythonPackages; [ + lz4 + ])) + ]; + dontUnpack = true; + installPhase = "install -Dm755 ${./unzip_mozlz4.py} $out/bin/unzip_mozlz4"; + }; + extract_cookies = sysLib.writeShellScript { + name = "extract_cookies"; + src = ./extract_cookies.sh; + dependencies = with pkgs; [ + bash + sqlite + mktemp + coreutils + ]; + }; +in { + inherit unzip_mozlz4 extract_cookies; +} diff --git a/modules/home.legacy/conf/firefox/scripts/extract_cookies.sh b/modules/home.legacy/conf/firefox/scripts/extract_cookies.sh new file mode 100755 index 00000000..e3d50d43 --- /dev/null +++ b/modules/home.legacy/conf/firefox/scripts/extract_cookies.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# copied from https://superuser.com/a/1239036 +# extract_cookies.sh: +# +# Convert from Firefox's cookies.sqlite format to Netscape cookies, +# which can then be used by wget and curl. (Why don't wget and curl +# just use libsqlite if it's installed? Mysteries abound.) +# +# Note: This script reads directly from the standard cookie jar file, +# which means cookies which are kept only in memory ("session cookies") +# will not be extracted. You will need an extension to do that. + +# USAGE: +# +# $ extract_cookies.sh > /tmp/cookies.txt +# or +# $ extract_cookies.sh ~/.mozilla/firefox/*default*/cookies.sqlite > /tmp/cookies.txt + +# USING WITH WGET: +# $ wget --load-cookies=/tmp/cookies.txt http://example.com + +# USING WITH CURL: +# $ curl --cookie /tmp/cookies.txt http://example.com + +# Note: If you do not specify an SQLite filename, this script will +# intelligently find it for you. +# +# A) Usually it will check all profiles under ~/.mozilla/firefox/ and +# use the cookies.sqlite that was updated most recently. +# +# B) If you've redirected stdin (with < or |) , then that will be used. + +# HISTORY: I believe this is circa 2010 from: +# http://slacy.com/blog/2010/02/using-cookies-sqlite-in-wget-or-curl/ +# However, that site is down now. + +# Cleaned up by Hackerb9 (2017) to be more robust and require less typing. + +cleanup() { + rm -f "$TMPFILE" + exit 0 +} +trap cleanup EXIT INT QUIT TERM + +if [ "$#" -ge 1 ]; then + SQLFILE="$1" +else + SQLFILE="$HOME/.mozilla/firefox/default/cookies.sqlite" +fi + +if ! [ -r "$SQLFILE" ]; then + echo "Error. File $SQLFILE is not readable." >&2 + exit 1 +fi + +# We have to copy cookies.sqlite, because FireFox has a lock on it +TMPFILE=$(mktemp /tmp/cookies.sqlite.XXXXXXXXXX) +cat "$SQLFILE" >>"$TMPFILE" + +# This is the format of the sqlite database: +# CREATE TABLE moz_cookies (id INTEGER PRIMARY KEY, name TEXT, value TEXT, host TEXT, path TEXT,expiry INTEGER, lastAccessed INTEGER, isSecure INTEGER, isHttpOnly INTEGER); + +echo "# Netscape HTTP Cookie File" +sqlite3 -separator $'\t' "$TMPFILE" < ") diff --git a/modules/home.legacy/conf/firefox/scripts/update_extensions.sh b/modules/home.legacy/conf/firefox/scripts/update_extensions.sh new file mode 100755 index 00000000..86bd843c --- /dev/null +++ b/modules/home.legacy/conf/firefox/scripts/update_extensions.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +tmp=$(mktemp) +cat <"$tmp" + darkreader:navbar + keepassxc-browser:navbar + vhack-libredirect:navbar + torproject-snowflake:navbar + tridactyl-vim:menupanel + ublock-origin:menupanel +EOF + +# The bin is provided in the devshell; +# The cat execution should be unquoted; +# shellcheck disable=SC2046 +generate_extensions $(cat "$tmp") >"$(dirname "$0")"/../config/extensions/extensions.json + +rm "$tmp" -- cgit 1.4.1