{
  pkgs,
  lib,
  osConfig,
  config,
  ...
}:
lib.mkIf osConfig.programs.firefox.enable {
  programs.firefox = {
    enable = true;
    # Installed by nixpkgs module
    package = osConfig.programs.firefox.package;
    profiles.${config.home.username} = {
      name = config.home.username;
      isDefault = true;
      userContent = # css
        ''
          /* Sidebery */
          @-moz-document url("moz-extension://d1d9847c-2bad-429f-9366-56db49b8c3d6/sidebar/sidebar.html")
          {
            #root {
              --tabs-indent: 0px !important;
            }

            #root:hover {
              --tabs-indent: 30px !important;
            }
          }
        '';
      userChrome = # css
        ''
          /* Hides the native tabs, sidebar header and splitter */
          #TabsToolbar,
          #sidebar-splitter,
          #sidebar-header {
            display: none;
          }

          #sidebar-box {
            --sidebar-normal-width: 35px;
            --sidebar-hovered-width: 300px;
            --sidebar-transition-speed: 200ms;
            --sidebar-collapse-delay: 300ms;
            --sidebar-transition-type: linear;
            --browser-area-z-index-sidebar: 3;

            position: relative;
            min-width: var(--sidebar-normal-width) !important;
            width: var(--sidebar-normal-width) !important;
            max-width: var(--sidebar-normal-width) !important;
            z-index: var(--browser-area-z-index-sidebar);
          }

          #sidebar-box[positionend] {
            direction: rtl;
          }
          #sidebar-box[positionend] > * {
            direction: ltr;
          }

          #sidebar-box[positionend]:-moz-locale-dir(rtl) {
            direction: ltr;
          }
          #sidebar-box[positionend]:-moz-locale-dir(rtl) > * {
            direction: rtl;
          }

          #main-window[sizemode="fullscreen"] #sidebar-box {
            --sidebar-normal-width: 1px;
          }

          #sidebar {
            transition: min-width var(--sidebar-transition-speed)
              var(--sidebar-transition-type) var(--sidebar-collapse-delay) !important;
            min-width: var(--sidebar-normal-width) !important;
            will-change: min-width;
          }
          #sidebar-box:hover > #sidebar {
            min-width: var(--sidebar-hovered-width) !important;
            transition-delay: 100ms !important;
          }
        '';
      search = {
        default = "DuckDuckGo";
        force = true;
        engines =
          let
            nixicon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
            iconUpdateInterval = 24 * 60 * 60 * 1000; # every day
          in
          {
            "NixOS Packages" = {
              urls = [ { template = "https://search.nixos.org/packages?query={searchTerms}"; } ];
              icon = nixicon;
              definedAliases = [
                "@nixpkg"
                "@nixpkgs"
              ];
            };
            "NixOS Wiki" = {
              urls = [ { template = "https://wiki.nixos.org/w/index.php?search={searchTerms}"; } ];
              icon = nixicon;
              definedAliases = [ "@nixwiki" ];
            };
            "NixOS Options" = {
              urls = [ { template = "https://search.nixos.org/options?query={searchTerms}"; } ];
              icon = nixicon;
              definedAliases = [ "@nixoptions" ];
            };
            "Arch Wiki" = {
              urls = [
                { template = "https://wiki.archlinux.org/index.php?title=Special:Search&search={searchTerms}"; }
              ];
              iconUpdateURL = "https://wiki.archlinux.org/favicon.ico";
              updateInterval = iconUpdateInterval;
              definedAliases = [ "@archwiki" ];
            };
            "DuckDuckGo" = {
              urls = [ { template = "https://duckduckgo.com/?q={searchTerms}"; } ];
              iconUpdateURL = "https://duckduckgo.com/favicon.ico";
              updateInterval = iconUpdateInterval;
              definedAliases = [
                "@duckduckgo"
                "@ddg"
              ];
            };
            "MyNixOS" = {
              urls = [ { template = "https://mynixos.com/search?q={searchTerms}"; } ];
              iconUpdateURL = "https://mynixos.com/favicon.ico";
              updateInterval = iconUpdateInterval;
              definedAliases = [
                "@hm"
                "@mynixos"
              ];
            };
            "stackoverflow" = {
              urls = [ { template = "https://stackoverflow.com/search?q={searchTerms}"; } ];
              iconUpdateURL = "https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico";
              updateInterval = iconUpdateInterval;
              definedAliases = [ "@stackoverflow" ];
            };

            Noogle = {
              urls = [ { template = "https://noogle.dev/q?term={searchTerms}"; } ];
              icon = nixicon;
              definedAliases = [
                "@noogle"
                "@ngl"
              ];
            };
          };
      };
    };
  };
}
