about summary refs log tree commit diff stats
path: root/home-manger/firefox/default.nix
blob: 5e9b96325c1c48797dd0e7f78ba977ba855f824e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# vim: ts=2
{
  config,
  pkgs,
  lib,
  stdenv,
  ...
}: let
  user_js_override = "./settings/override.js";
  user_js = lib.runCommand "user.js" {} ''
    mkdir $out;
    ${config.inputs.strip_js_comments}/bin ${config.inputs.user_js} > $out/user.js;
    cat ${user_js_override} >> $out/user.js;
    sed 's/user_pref(\(.*\)",\(.*\));/\1" = \2;/' $out/user.js > $out/user.nix;
  '';

  # source: https://gitlab.com/rycee/nur-expressions/-/blob/master/pkgs/firefox-addons/default.nix
  buildFirefoxXpiAddon = {
    pname,
    version,
    addonId,
    url,
    sha256,
    meta,
    ...
  }:
    builtins.stdenv.mkDerivation {
      name = "${pname}-${version}";

      inherit meta;

      src = builtins.fetchurl {inherit url sha256;};

      preferLocalBuild = true;
      allowSubstitutes = true;

      buildCommand = ''
        dst="$out/share/mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
        mkdir -p "$dst"
        install -v -m644 "$src" "$dst/${addonId}.xpi"
      '';
    };

  settings =
    pkgs.lib.recursiveUpdate
    {
      # Allow my custom css
      "toolkit.legacyUserProfileCustomizations.stylesheets" = true;

      # might improve performance TODO
      "gfx.webrender.all" = true;

      # disable updates (pretty pointless with nix)
      "extensions.update.autoUpdateDefault" = false;
      "extensions.update.enabled" = false;
      "app.update.channel" = "default";

      "browser.ctrlTab.recentlyUsedOrder" = false;

      "browser.download.useDownloadDir" = true;
      "browser.download.dir" = "${config.user.soisha.home}/media/downloads";
      "browser.download.folderList" = 2; # TODO
      "browser.download.viewableInternally.typeWasRegistered.svg" = true;
      "browser.download.viewableInternally.typeWasRegistered.webp" = true;
      "browser.download.viewableInternally.typeWasRegistered.xml" = true;

      # TODO what does this do?
      "browser.search.widget.inNavBar" = true;

      "browser.shell.checkDefaultBrowser" = false;
      "browser.tabs.loadInBackground" = true;
      "browser.urlbar.placeholderName" = "Brave";

      "general.autoScroll" = true;

      # Set the tabs and bookmarks
      "browser.tabs.inTitlebar" = 1;
      "browser.toolbars.bookmarks.visibility" = "always";

      # Theme
      "extensions.activeThemeID" = "firefox-alpenglow@mozilla.org";
      "extensions.extensions.activeThemeID" = "firefox-alpenglow@mozilla.org";

      # highlight all entries when searching
      "findbar.highlightAll" = true;

      # TODO
      #"extensions.webcompat.enable_picture_in_picture_overrides" = true;
      #"extensions.webcompat.enable_shims" = true;
      #"extensions.webcompat.perform_injections" = true;
      #"extensions.webcompat.perform_ua_overrides" = true;

      # onlykey / copied from a yubikey config
      #"security.webauth.u2f" = true;
      #"security.webauth.webauthn" = true;
      #"security.webauth.webauthn_enable_softtoken" = true;
      #"security.webauth.webauthn_enable_usbtoken" = true;
    }
    builtins.readFile
    "${user_js}/user.nix";
in {
  home-manager.users.${config.soisha.user.username} = {
    packages = [
      pkgs.firefox-wayland
    ];
    sessionVariables = {
      # improve touch input & make scrolling smother
      MOZ_USE_XINPUT2 = "1";
      # improve wayland support
      MOZ_ENABLE_WAYLAND = 1;
      XDG_CURRENT_DESKTOP = "river";
    };
    xdg.mimeApps = {
      enable = true;
      defaultApplications = {
        "text/html" = ["firefox.desktop"];
        "x-scheme-handler/http" = ["firefox.desktop"];
        "x-scheme-handler/https" = ["firefox.desktop"];
        "x-scheme-handler/about" = ["firefox.desktop"];
        "x-scheme-handler/unknown" = ["firefox.desktop"];
      };
    };
    programs.firefox = {
      enable = true;
      package = pkgs.firefox;
      extensions = builtins.map buildFirefoxXpiAddon (lib.attrValues (lib.importJSON ./extensions.json));
      profile."default" = {
        isDefault = true;
        id = 0;
        name = "default";

        userChrome = builtins.readFile "./chrome/userChrome.css";

        search = {
          default = "Brave Search";
          force = true;

          engines = {
            "Brave Search" = {
              urls = [{template = "https://search.brave.com/search?q={searchTerms}";}];
              iconUpdateURL = "https://cdn.search.brave.com/serp/v1/static/brand/8eabe183f0d1f2cb3e2916b7b20c310efd196d740c8cecd341732fcd396fb665-apple-touch-icon.png";
              updateInterval = 24 * 60 * 60 * 1000; # every day
              definedAliases = ["@bs"];
            };

            "Nix Packages" = {
              urls = [
                {
                  template = "https://search.nixos.org/packages";
                  params = [
                    {
                      name = "type";
                      value = "packages";
                    }
                    {
                      name = "query";
                      value = "{searchTerms}";
                    }
                  ];
                }
              ];

              icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
              definedAliases = ["@np"];
            };

            "NixOS Wiki" = {
              urls = [{template = "https://nixos.wiki/index.php?search={searchTerms}";}];
              iconUpdateURL = "https://nixos.wiki/favicon.png";
              updateInterval = 24 * 60 * 60 * 1000; # every day
              definedAliases = ["@nw"];
            };
            "Bing".metaData.hidden = true;
            "Google".metaData.hidden = true;
            "Amazon.de".metaData.hidden = true;
          };
        };

        bookmarks = [
          {
            name = "Rust::std";
            # TODO
            url = "file:///home/dt/.local/share/rustup/toolchains/stable-x86_64-unknown-linux-gnu/share/doc/rust/html/std/all.html";
          }

          {
            name = "Feed - Piped";
            url = "https://piped.kavin.rocks/feed";
          }

          {
            name = "DeepL Translate";
            url = "https://www.deepl.com/translator#en/de/test";
          }

          {
            name = "Google Scholar";
            url = "https://scholar.google.com/";
          }

          {
            name = "ArchWiki";
            url = "https://wiki.archlinux.org/";
          }

          {
            name = "Arch Package ";
            url = "https://archlinux.org/packages/";
          }

          {
            name = "layout.css.devPixelsPerPx";
            url = "about:config";
          }
        ];
        inherit settings;
      };
    };
  };
}