{ pkgs, ... }:
let
  lock-false = {
    Value = false;
    Status = "locked";
  };
in
{
  programs.firefox = {
    enable = true;
    package = pkgs.wrapFirefox pkgs.firefox-unwrapped {
      extraPolicies = {
        DisableTelemetry = true;
        DisableFirefoxStudies = true;
        DisplayBookmarksToolbar = "never"; # alternatives: "always" or "newtab"
        EnableTrackingProtection = {
          Value = true;
          Locked = true;
          Cryptomining = true;
          Fingerprinting = true;
        };
        ExtensionSettings = {
          "@contain-google" = {
            install_url =
              "https://addons.mozilla.org/firefox/downloads/latest/google-container/latest.xpi";
            installation_mode = "force_installed";
          };
          "{ea4204c0-3209-4116-afd2-2a208e21a779}" = {
            install_url =
              "https://addons.mozilla.org/firefox/downloads/latest/enable-bing-chat/latest.xpi";
            installation_mode = "force_installed";
          };
          "{3e4d2037-d300-4e95-859d-3cba866f46d3}" = {
            install_url =
              "https://addons.mozilla.org/firefox/downloads/latest/private-internet-access-ext/latest.xpi";
            installation_mode = "force_installed";
          };
          "{c7c120ff-2878-4e59-a5a3-cd4d1655bc13}" = {
            install_url = "file://${./files/signed.xpi}";
            installation_mode = "force_installed";
          };
        };
        Preferences = {
          "browser.disableResetPrompt" = true;
          "browser.download.panel.shown" = true;
          "browser.shell.checkDefaultBrowser" = false;
          "browser.tabs.inTitlebar" = 0;
          "browser.shell.defaultBrowserCheckCount" = 1;
          "browser.startup.homepage" = "https://start.duckduckgo.com";
          "browser.compactmode.show" = true;
          "browser.uidensity" = 1;
          "extensions.update.enabled" = false;
          "extensions.pocket.enabled" = lock-false;
          "extensions.autoDisableScopes" = 0;
          "browser.contentblocking.category" = {
            Value = "strict";
            Status = "locked";
          };
          "browser.uiCustomization.state" = ''
            {"placements":{"widget-overflow-fixed-list":["fxa-toolbar-menu-button","developer-button"],"unified-extensions-area":["sponsorblocker_ajay_app-browser-action","_testpilot-containers-browser-action","_531906d3-e22f-4a6c-a102-8057b88a1a63_-browser-action","beyond20_kakaroto_homelinux_net-browser-action","_d7742d87-e61d-4b78-b8a1-b469842139fa_-browser-action","_contain-facebook-browser-action","jid1-kkzogwgsw3ao4q_jetpack-browser-action","jid1-mnnxcxisbpnsxq_jetpack-browser-action","_74145f27-f039-47ce-a470-a662b129930a_-browser-action","chrome-gnome-shell_gnome_org-browser-action","_ea4204c0-3209-4116-afd2-2a208e21a779_-browser-action","_f209234a-76f0-4735-9920-eb62507a54cd_-browser-action","_762f9885-5a13-4abd-9c77-433dcd38b8fd_-browser-action","display-anchors_robwu_nl-browser-action","firefoxcolor_mozilla_com-browser-action","search_kagi_com-browser-action","_7a7a4a92-a2a0-41d1-9fd7-1e92480d612d_-browser-action"],"nav-bar":["back-button","forward-button","stop-reload-button","urlbar-container","downloads-button","_446900e4-71c2-419f-a6a7-df9c091e268b_-browser-action","_12cf650b-1822-40aa-bff0-996df6948878_-browser-action","_3e4d2037-d300-4e95-859d-3cba866f46d3_-browser-action","save-as-pdf-ff_pdfcrowd_com-browser-action","user-agent-switcher_ninetailed_ninja-browser-action","_d66c8515-1e0d-408f-82ee-2682f2362726_-browser-action","ublock0_raymondhill_net-browser-action","reset-pbm-toolbar-button","adguardadblocker_adguard_com-browser-action","unified-extensions-button"],"toolbar-menubar":["menubar-items"],"TabsToolbar":["tabbrowser-tabs","new-tab-button","alltabs-button"],"PersonalToolbar":["import-button","personal-bookmarks"]},"seen":["developer-button","profiler-button","chrome-gnome-shell_gnome_org-browser-action","_446900e4-71c2-419f-a6a7-df9c091e268b_-browser-action","_74145f27-f039-47ce-a470-a662b129930a_-browser-action","_contain-facebook-browser-action","_testpilot-containers-browser-action","jid1-kkzogwgsw3ao4q_jetpack-browser-action","jid1-mnnxcxisbpnsxq_jetpack-browser-action","ublock0_raymondhill_net-browser-action","_531906d3-e22f-4a6c-a102-8057b88a1a63_-browser-action","beyond20_kakaroto_homelinux_net-browser-action","_12cf650b-1822-40aa-bff0-996df6948878_-browser-action","_3e4d2037-d300-4e95-859d-3cba866f46d3_-browser-action","save-as-pdf-ff_pdfcrowd_com-browser-action","_d7742d87-e61d-4b78-b8a1-b469842139fa_-browser-action","user-agent-switcher_ninetailed_ninja-browser-action","_d66c8515-1e0d-408f-82ee-2682f2362726_-browser-action","_ea4204c0-3209-4116-afd2-2a208e21a779_-browser-action","adguardadblocker_adguard_com-browser-action","_f209234a-76f0-4735-9920-eb62507a54cd_-browser-action","_762f9885-5a13-4abd-9c77-433dcd38b8fd_-browser-action","sponsorblocker_ajay_app-browser-action","display-anchors_robwu_nl-browser-action","firefoxcolor_mozilla_com-browser-action","search_kagi_com-browser-action","_7a7a4a92-a2a0-41d1-9fd7-1e92480d612d_-browser-action"],"dirtyAreaCache":["nav-bar","PersonalToolbar","toolbar-menubar","TabsToolbar","widget-overflow-fixed-list","unified-extensions-area"],"currentVersion":20,"newElementCount":11}'';
          "privacy.trackingprotection.enabled" = true;
        };
      };
    };
    profiles = {
      default = {
        id = 0;
        name = "default";
        isDefault = true;
        search = {
          force = true;
          default = "DuckDuckGo";
          order = [ "DuckDuckGo" "Google" ];
        };
        extensions = with pkgs.nur.repos.rycee.firefox-addons; [
          ublock-origin
          bitwarden
          privacy-badger
          beyond-20
          display-_anchors
          facebook-container
          multi-account-containers
          istilldontcareaboutcookies
          return-youtube-dislikes
          sponsorblock
          unpaywall
          vimium
        ];
      };
    };
  };

  xdg.mimeApps.defaultApplications = {
    "application/json" = [ "firefox.desktop" ];
    "application/x-extension-htm" = [ "firefox.desktop" ];
    "application/x-extension-html" = [ "firefox.desktop" ];
    "application/x-extension-shtml" = [ "firefox.desktop" ];
    "application/x-extension-xhtml" = [ "firefox.desktop" ];
    "application/x-extension-xht" = [ "firefox.desktop" ];
    "application/xhtml+xml" = [ "firefox.desktop" ];
    "text/html" = [ "firefox.desktop" ];
    "text/xml" = [ "firefox.desktop" ];
    "x-scheme-handler/about" = [ "firefox.desktop" ];
    "x-scheme-handler/ftp" = [ "firefox.desktop" ];
    "x-scheme-handler/http" = [ "firefox.desktop" ];
    "x-scheme-handler/unknown" = [ "firefox.desktop" ];
    "x-scheme-handler/https" = [ "firefox.desktop" ];
  };
}
