diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index b5d6fcf..304cd4b 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -4,8 +4,8 @@ config, ... }: let + inherit (builtins) readFile; inherit (config.local.systemVars) username; - toINI = lib.generators.toINI {}; betterfox = pkgs.fetchFromGitHub { owner = "yokoffing"; @@ -13,161 +13,152 @@ rev = "e026ed7d3a763c5d3f96c2680d7bc3340831af4f"; hash = "sha256-hpkEO5BhMVtINQG8HN4xqfas/R6q5pYPZiFK8bilIDs="; }; - - firefox = pkgs.wrapFirefox pkgs.firefox-esr-unwrapped { - extraPolicies = { - DisableTelemetry = true; - DisablePocket = true; - DisableFeedbackCommands = true; - DisableFirefoxStudies = true; - OfferToSaveLogins = false; - OffertosaveloginsDefault = false; - PasswordManagerEnabled = false; - SearchSuggestEnabled = true; - FirefoxHome = { - Pocket = false; - Snippets = false; - }; - - SearchEngines.Default = "SearxNG"; - SearchEngines.Add = [ - { - Name = "SearxNG"; - URLTemplate = "https://search.nezia.dev/search?q={searchTerms}"; - Method = "GET"; - SuggestURLTemplate = "https://search.nezia.dev/autocompleter?q={searchTerms}"; - } - { - Name = "Nix Packages"; - Alias = "@np"; - URLTemplate = "https://search.nixos.org/packages?channel=unstable&query={searchTerms}"; - Method = "GET"; - } - { - Name = "Nix Options"; - Alias = "@no"; - URLTemplate = "https://search.nixos.org/options?channel=unstable&query={searchTerms}"; - Method = "GET"; - } - { - Name = "NixOS Wiki"; - Alias = "@nw"; - URLTemplate = "https://wiki.nixos.org/w/index.php?search={searchTerms}"; - Method = "GET"; - } - { - Name = "Home Manager Options"; - Alias = "@hmo"; - URLTemplate = "https://home-manager-options.extranix.com/?query={searchTerms}&release=master"; - Method = "GET"; - } - { - Name = "ProtonDB"; - Alias = "@pdb"; - URLTemplate = "https://www.protondb.com/search?q={searchTerms}"; - Method = "GET"; - } - { - Name = "Noogle"; - Alias = "@ng"; - URLTemplate = "https://noogle.dev/q?term={searchTerms}"; - } - { - Name = "GitHub Nix"; - Alias = "@ghn"; - URLTemplate = "https://github.com/search?q=language:nix NOT is:fork {searchTerms}&type=code"; - } - ]; - - # https://github.com/Sly-Harvey/NixOS/blob/f9da2691ea46565256ad757959cfc26ec6cee10d/modules/programs/browser/firefox/default.nix#L58-L163 - "3rdparty".Extensions = { - "addon@darkreader.org" = { - permissions = ["internal:privateBrowsingAllowed"]; - enabled = true; - automation = { - enabled = true; - behavior = "OnOff"; - mode = "system"; - }; - detectDarkTheme = true; - enabledByDefault = true; - changeBrowserTheme = false; - enableForProtectedPages = true; - fetchNews = false; - previewNewDesign = true; - }; - "uBlock0@raymondhill.net" = { - permissions = ["internal:privateBrowsingAllowed"]; - advancedSettings = [ - [ - "userResourcesLocation" - "https://raw.githubusercontent.com/pixeltris/TwitchAdSolutions/master/video-swap-new/video-swap-new-ublock-origin.js" - ] - ]; - adminSettings = { - userSettings = { - uiTheme = "dark"; - advancedUserEnabled = true; - userFiltersTrusted = true; - importedLists = [ - "https://raw.githubusercontent.com/laylavish/uBlockOrigin-HUGE-AI-Blocklist/main/list.txt" - ]; - selectedFilterLists = [ - "FRA-0" - "adguard-cookies" - "adguard-mobile-app-banners" - "adguard-other-annoyances" - "adguard-popup-overlays" - "adguard-social" - "adguard-spyware-url" - "adguard-widgets" - "easylist" - "easylist-annoyances" - "easylist-chat" - "easylist-newsletters" - "easylist-notifications" - "easyprivacy" - "fanboy-cookiemonster" - "https://filters.adtidy.org/extension/ublock/filters/3.txt" - "https://github.com/DandelionSprout/adfilt/raw/master/LegitimateURLShortener.txt" - "plowe-0" - "ublock-annoyances" - "ublock-badware" - "ublock-cookies-adguard" - "ublock-cookies-easylist" - "ublock-filters" - "ublock-privacy" - "ublock-quick-fixes" - "ublock-unbreak" - "urlhaus-1" - "https://raw.githubusercontent.com/laylavish/uBlockOrigin-HUGE-AI-Blocklist/main/list.txt" - ]; - }; - }; - }; - }; - }; - }; in { config = lib.mkIf config.local.profiles.desktop.enable { hjem.users.${username} = { - packages = [firefox]; - files = { - ".mozilla/firefox/profiles.ini".text = toINI { - Profile0 = { - # creates user profile and sets it as default - Name = "${username}"; - IsRelative = 1; - Path = "${username}"; - Default = 1; + programs.firefox = { + enable = true; + inherit username; + + policies = { + DisableTelemetry = true; + DisablePocket = true; + DisableFeedbackCommands = true; + DisableFirefoxStudies = true; + OfferToSaveLogins = false; + OffertosaveloginsDefault = false; + PasswordManagerEnabled = false; + SearchSuggestEnabled = true; + FirefoxHome = { + Pocket = false; + Snippets = false; + }; + + SearchEngines.Default = "SearxNG"; + SearchEngines.Add = [ + { + Name = "SearxNG"; + URLTemplate = "https://search.nezia.dev/search?q={searchTerms}"; + Method = "GET"; + SuggestURLTemplate = "https://search.nezia.dev/autocompleter?q={searchTerms}"; + } + { + Name = "Nix Packages"; + Alias = "@np"; + URLTemplate = "https://search.nixos.org/packages?channel=unstable&query={searchTerms}"; + Method = "GET"; + } + { + Name = "Nix Options"; + Alias = "@no"; + URLTemplate = "https://search.nixos.org/options?channel=unstable&query={searchTerms}"; + Method = "GET"; + } + { + Name = "NixOS Wiki"; + Alias = "@nw"; + URLTemplate = "https://wiki.nixos.org/w/index.php?search={searchTerms}"; + Method = "GET"; + } + { + Name = "Home Manager Options"; + Alias = "@hmo"; + URLTemplate = "https://home-manager-options.extranix.com/?query={searchTerms}&release=master"; + Method = "GET"; + } + { + Name = "ProtonDB"; + Alias = "@pdb"; + URLTemplate = "https://www.protondb.com/search?q={searchTerms}"; + Method = "GET"; + } + { + Name = "Noogle"; + Alias = "@ng"; + URLTemplate = "https://noogle.dev/q?term={searchTerms}"; + } + { + Name = "GitHub Nix"; + Alias = "@ghn"; + URLTemplate = "https://github.com/search?q=language:nix NOT is:fork {searchTerms}&type=code"; + } + ]; + + # https://github.com/Sly-Harvey/NixOS/blob/f9da2691ea46565256ad757959cfc26ec6cee10d/modules/programs/browser/firefox/default.nix#L58-L163 + "3rdparty".Extensions = { + "addon@darkreader.org" = { + permissions = ["internal:privateBrowsingAllowed"]; + enabled = true; + automation = { + enabled = true; + behavior = "OnOff"; + mode = "system"; + }; + detectDarkTheme = true; + enabledByDefault = true; + changeBrowserTheme = false; + enableForProtectedPages = true; + fetchNews = false; + previewNewDesign = true; + }; + "uBlock0@raymondhill.net" = { + permissions = ["internal:privateBrowsingAllowed"]; + advancedSettings = [ + [ + "userResourcesLocation" + "https://raw.githubusercontent.com/pixeltris/TwitchAdSolutions/master/video-swap-new/video-swap-new-ublock-origin.js" + ] + ]; + adminSettings = { + userSettings = { + uiTheme = "dark"; + advancedUserEnabled = true; + userFiltersTrusted = true; + importedLists = [ + "https://raw.githubusercontent.com/laylavish/uBlockOrigin-HUGE-AI-Blocklist/main/list.txt" + ]; + selectedFilterLists = [ + "FRA-0" + "adguard-cookies" + "adguard-mobile-app-banners" + "adguard-other-annoyances" + "adguard-popup-overlays" + "adguard-social" + "adguard-spyware-url" + "adguard-widgets" + "easylist" + "easylist-annoyances" + "easylist-chat" + "easylist-newsletters" + "easylist-notifications" + "easyprivacy" + "fanboy-cookiemonster" + "https://filters.adtidy.org/extension/ublock/filters/3.txt" + "https://github.com/DandelionSprout/adfilt/raw/master/LegitimateURLShortener.txt" + "plowe-0" + "ublock-annoyances" + "ublock-badware" + "ublock-cookies-adguard" + "ublock-cookies-easylist" + "ublock-filters" + "ublock-privacy" + "ublock-quick-fixes" + "ublock-unbreak" + "urlhaus-1" + "https://raw.githubusercontent.com/laylavish/uBlockOrigin-HUGE-AI-Blocklist/main/list.txt" + ]; + }; + }; + }; }; }; - ".mozilla/firefox/${username}/user.js".text = builtins.concatStringsSep "\n" [ - (builtins.readFile "${betterfox}/user.js") - (builtins.readFile "${betterfox}/Securefox.js") - (builtins.readFile "${betterfox}/Fastfox.js") - (builtins.readFile "${betterfox}/Peskyfox.js") - (builtins.readFile "${betterfox}/Smoothfox.js") + + extraConfig = builtins.concatStringsSep "\n" [ + (readFile "${betterfox}/user.js") + (readFile "${betterfox}/Securefox.js") + (readFile "${betterfox}/Fastfox.js") + (readFile "${betterfox}/Peskyfox.js") + (readFile "${betterfox}/Smoothfox.js") ]; }; }; diff --git a/shared/modules/hjem/collection/programs/firefox.nix b/shared/modules/hjem/collection/programs/firefox.nix new file mode 100644 index 0000000..3133295 --- /dev/null +++ b/shared/modules/hjem/collection/programs/firefox.nix @@ -0,0 +1,74 @@ +{ + lib, + pkgs, + config, + ... +}: let + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) attrs lines package str; + + toINI = lib.generators.toINI {}; + + cfg = config.programs.firefox; + firefox = pkgs.wrapFirefox cfg.package { + extraPolicies = cfg.policies; + }; +in { + options.programs.firefox = { + enable = mkEnableOption "firefox module."; + package = mkOption { + type = package; + default = pkgs.firefox-esr-unwrapped; + example = pkgs.firefox-unwrapped; + description = '' + The Firefox package to use. As hjem's module implementation of Firefox uses wrapping, this package + is expected to be one of the unwrapped versions. Changing this is not recommended, as some policies + (i.e. SearchEngines) are only available on the ESR version of Firefox. + ''; + }; + policies = mkOption { + type = attrs; + default = {}; + example = { + CaptivePortal = false; + DisableFirefoxStudies = true; + DisablePocket = true; + DisableTelemetry = true; + DisableFirefoxAccounts = true; + }; + description = '' + An attribute set of policies to add to Firefox. The full list of policies can be found + [here](https://mozilla.github.io/policy-templates/). + ''; + }; + extraConfig = mkOption { + type = lines; + default = ""; + description = '' + Extra preferences to add to user.js. + ''; + }; + + username = mkOption { + type = str; + example = "user"; + description = '' + Name of the Firefox profile to be created. + ''; + }; + }; + config = lib.mkIf cfg.enable { + packages = [firefox]; + files = { + ".mozilla/firefox/profiles.ini".text = toINI { + Profile0 = { + Name = "${cfg.username}"; + IsRelative = 1; + Path = "${cfg.username}"; + Default = 1; + }; + }; + ".mozilla/firefox/${cfg.username}/user.js".text = cfg.extraConfig; + }; + }; +}