summary refs log tree commit diff
path: root/mixins/firefox/default.nix
blob: e3fd84e293176b74383258a56db7b6cdc3146672 (plain)
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
let
  profile = "default";
  prf = ".mozilla/firefox/${profile}";
  extstorage = "${prf}/browser-extension-data";
in
  {
    config,
    inputs,
    pkgs,
    lib,
    ...
  }: {
    home-manager.users.tzlil = let
      # gives me access to addonId and crap
      firefox-addons = pkgs.callPackage (pkgs.applyPatches {
        src = inputs.firefox-addons;
        patches = [./addons-passthru.patch];
        name = "firefox-addons-patched";
      }) {};
      addons = config.home-manager.users.tzlil.programs.firefox.profiles.${profile}.extensions;
    in {
      /*
      TODO
      figure out if you like sidebery or TST more
      if sidebery: figure out where options are stored so you can set colors declaratively and also tree groups
      also figure out how to make ctrl+e for SB not conflict with vimium, maybe will rebind to F1
      figure out the search engine crap, i have them hidden but id like them removed completely, Extensions.Uninstall and SearchEngines.Remove did nothing
      incorporate user.js instead of hardcoding some shit myself

      strace -f -t -e trace=file firefox | rg -e "\"/home/tzlil/(.mozilla.*?)\"" -o
      */
      home.file."${prf}/extension-preferences.json".text = builtins.toJSON (
        # i hate myself
        let
          recursiveMerge = attrList: let
            f = attrPath:
              builtins.zipAttrsWith (
                n: values:
                  if builtins.tail values == []
                  then builtins.head values
                  else if builtins.all builtins.isList values
                  then lib.unique (builtins.concatLists values)
                  else if builtins.all builtins.isAttrs values
                  then f (attrPath ++ [n]) values
                  else builtins.last values
              );
          in
            f [] attrList;
        in
          recursiveMerge
          [
            {
              "{3c078156-979c-498b-8990-85f7987dd929}" = {
                origins = ["<all_urls>"];
                permissions = ["proxy" "bookmarks" "tabHide" "clipboardWrite" "history" "downloads" "<all_urls>"];
              };

              "newtaboverride@agenedia.com" = {
                origins = ["https://www.soeren-hentzschel.at/*"];
                permissions = [];
              };
            }
            (lib.fold lib.mergeAttrs {} (map (x: {${x.passthru.addonId} = {permissions = ["internal:privateBrowsingAllowed"]; origins = [];};}) addons))
          ]
      );

      home.file."${prf}/extension-settings.json".text = builtins.toJSON {
        commands = {};
        default_search = {};
        homepageNotification = {};

        # gets rid of the first time notification
        newTabNotification = {
          "newtaboverride@agenedia.com" = {
            initialValue = false;
            precedenceList = [
              {
                enabled = true;
                id = "newtaboverride@agenedia.com";
                installDate = 1000;
                value = true;
              }
            ];
          };
        };
        prefs = {
          "network.networkPredictionEnabled" = {
            initialValue = {};
            precedenceList = [
              {
                enabled = true;
                id = "uBlock0@raymondhill.net";
                installDate = 1000;
                value = false;
              }
            ];
          };
          "privacy.containers" = {
            initialValue = {};
            precedenceList = [
              {
                enabled = true;
                id = "CanvasBlocker@kkapsner.de";
                installDate = 1000;
                value = "CanvasBlocker@kkapsner.de";
              }
            ];
          };
          "websites.hyperlinkAuditingEnabled" = {
            initialValue = {};
            precedenceList = [
              {
                enabled = true;
                id = "uBlock0@raymondhill.net";
                installDate = 1000;
                value = false;
              }
            ];
          };
        };
        tabHideNotification = {};
        url_overrides = {
          newTabURL = {
            initialValue = "about:newtab";
            precedenceList = [
              {
                enabled = true;
                id = "newtaboverride@agenedia.com";
                installDate = 1000;
                value = "moz-extension://5ba70e66-a52e-41b3-9364-b4f0a14f3854/html/newtab.html";
              }
            ];
          };
        };
        version = 3;
      };

      home.file."${extstorage}/redirector@einaregilsson.com/storage.js".text = builtins.toJSON {
        redirects =
          map ({
            includePattern,
            redirectUrl,
            description,
          }: {
            appliesTo = ["main_frame"];
            inherit description;
            disabled = false;
            error = null;
            exampleResult = "";
            exampleUrl = "";
            excludePattern = "";
            grouped = false;
            inherit includePattern;
            patternDesc = "";
            patternType = "W";
            processMatches = "noProcessing";
            inherit redirectUrl;
          }) [
            {
              includePattern = "https://*youtube.com/watch?*v=*";
              redirectUrl = "https://yewtu.be/watch?$2v=$3}";
              description = "invidious";
            }
            {
              includePattern = "https://*youtube.com/results?*search_query=*";
              redirectUrl = "https://yewtu.be/search?$2q=$3";
              description = "invidious search";
            }
          ];
        enableNotifications = false;
      };
      home.file."${extstorage}/newtaboverride@agenedia.com/storage.js".text = builtins.toJSON {
        url = "https://lobste.rs";
      };

      programs.firefox = {
        enable = true;
        package = pkgs.firefox-wayland.override {
          extraPolicies = {
                    CaptivePortal = false;
        DisableFirefoxStudies = true;
        DisablePocket = true;
        DisableTelemetry = true;
        DisableFirefoxAccounts = true;
        FirefoxHome = {
          Pocket = false;
          Snippets = false;
        };
        UserMessaging = {
          ExtensionRecommendations = false;
          SkipOnboarding = true;
        };
            OverrideFirstRunPage = "";
            Extensions.Install = map (x: x.src.outPath) config.home-manager.users.tzlil.programs.firefox.profiles."default".extensions;
          };
        };
        profiles.default = {
          userChrome = builtins.readFile ./userChrome.css;
          search = {
            default = "DuckDuckGo";
            force = true;
            engines = {
              "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"];
              };
              "Home Manager" = {
                urls = [
                  {
                    template = "https://mipmip.github.io/home-manager-option-search/";
                    params = [
                      {
                        name = "query";
                        value = "{searchTerms}";
                      }
                    ];
                  }
                ];

                icon = "${pkgs.nixos-icons}/share/icons/hicolor/scalable/apps/nix-snowflake.svg";
                definedAliases = ["!hm"];
              };
              "Invidious" = {
                urls = [
                  {
                    template = "https://yewtu.be/search";
                    params = [
                      {
                        name = "q";
                        value = "{searchTerms}";
                      }
                    ];
                  }
                ];

                iconUpdateURL = "https://invidious.io/favicon.ico";
                definedAliases = ["!yt"];
              };
            };
          };

          extraConfig = builtins.readFile (
            builtins.fetchurl {
              url = "https://raw.githubusercontent.com/arkenfox/user.js/master/user.js";
              sha256 = "sha256:165c977fwncvrv0c8ddi633ckw97p3pkvjid5fj6j48smsv08axk";
            }
          ) + ''
          user_pref('keyword.enabled', true);
          user_pref("browser.startup.homepage", "https://lobste.rs");
          user_pref("browser.startup.page", 1);
          user_pref("privacy.resistFingerprinting", false);
          '';
          settings = {
            # for custom browser style
            "toolkit.legacyUserProfileCustomizations.stylesheets" = true;

            "browser.newtabpage.pinned" = [
              {url = "https://tzlil.net";}
            ];

            "extensions.activeThemeID" = "{e410fec2-1cbd-4098-9944-e21e708418af}";
            "svg.context-properties.content.enabled" = true;

            "browser.toolbars.bookmarks.visibility" = "always";
            "browser.uidensity" = 1;
            "browser.aboutConfig.showWarning" = false;
            "browser.shell.checkDefaultBrowser" = false;

            # always private mode
            # its what i had with mullvad, but mayb i will not do that anymore cuz its kinda annoying having to log back into everything always
            # but then i also need to keep more state
            # "browser.privatebrowsing.autostart" = true;

            # remove crap
            "browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts" = false;
            "browser.search.hiddenOneOffs" = "Google,Bing,Amazon.com,eBay,Twitter,Wikipedia (en)";

            "browser.download.dir" = config.home-manager.users.tzlil.xdg.userDirs.download;

            # for webconsole
            # "devtools.chrome.enabled" = true;
            # "general.config.filename" = "UserChrome.js";
            # "general.config.obscure_value" = 0;
            # "general.config.sandbox_enabled" = false;

            # might be neccesary for declaratively setting newtaboverride as the default newtab
            # "extensions.webextensions.uuids" = {
            # "newtaboverride@agenedia.com" = "5ba70e66-a52e-41b3-9364-b4f0a14f3854";
            # };
          };
          extensions = with firefox-addons; [
            # privacy crap
            ublock-origin
            clearurls
            privacy-possum
            skip-redirect
            # localcdn
            canvasblocker

            # dont need this, impermanence
            # history-cleaner

            # usability crap
            darkreader
            vimium
            # upgrade for new theme stuff
            (firefox-addons.buildFirefoxXpiAddon {
              pname = "sidebery";
              version = "v5.0.0rc4";
              addonId = "{3c078156-979c-498b-8990-85f7987dd929}";
              url = "https://github.com/mbnuqw/sidebery/releases/download/v5.0.0rc4/sidebery-5.0.0rc4.xpi";
              sha256 = "sha256-YsH9yYfGefClRS93dMV/eLMFuoPFKPrx0NL2hIv4dEk=";
              meta = with lib; {
                homepage = "https://github.com/mbnuqw/sidebery";
                description = "Tabs tree and bookmarks in sidebar with advanced containers configuration.";
                license = licenses.mit;
                platforms = platforms.all;
              };
            })
            redirector
            demodal
            kristofferhagen-nord-theme
            new-tab-override

            # misc
            snowflake
          ];
        };
      };
    };
  }