{ pkgs, ... }:
let
    lock-false = {
        Value = false;
        Status = "locked";
    };
in
    {
    programs.firefox = {
        enable = true;
        package = pkgs.wrapFirefox pkgs.firefox-unwrapped {
            pkcs11Modules = [
                pkgs.eid-mw
            ];
            extraPolicies = {
                DisableTelemetry = true;
                DisableFirefoxStudies = true;
                DisplayBookmarksToolbar = "never"; # alternatives: "always" or "newtab"
                EnableTrackingProtection = {
                    Value = true;
                    Locked = true;
                    Cryptomining = true;
                    Fingerprinting = true;
                };
                ExtensionSettings = {
                    "{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";
                    };
                    "privacy.trackingprotection.enabled" = true;
                };
            };
        };
        profiles = {
            default = {
                id = 0;
                name = "default";
                isDefault = true;
                search = {
                    force = true;
                    default = "ddg";
                    order = [ "ddg" "google" ];
                };
                extensions.packages = 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
                    google-container
                    duckduckgo-privacy-essentials
                ];
            };
        };
    };

    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" ];
    };
}
