summary refs log tree commit diff
path: root/mixins/firefox/absolute-minimum.nix
blob: d3ebe98f60e03736278b0c221f60830077fa6484 (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
let
  profile = "default";
  prf = ".mozilla/firefox/${profile}";
  extstorage = "${prf}/browser-extension-data";
in
  {
    config,
    inputs,
    pkgs,
    lib,
    ...
  }: {
    home-manager.users.tzlil = let
      firefox-addons = pkgs.callPackage (pkgs.applyPatches {
        src = inputs.firefox-addons;
        patches = [./addons-passthru.patch];
        name = "firefox-addons-patched";
      }) {};
      mozlz4 = n: x:
        pkgs.runCommand "${n}.lz4" {buildInputs = [pkgs.mozlz4a];} ''
          mozlz4a ${pkgs.writeTextFile {
            name = n;
            text = builtins.toJSON x;
          }} $out
        '';
      cfg = config.home-manager.users.tzlil.programs;
      addons = cfg.firefox.profiles.${profile}.extensions;
      extensionPath = "extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}";

      firefoxData =
        pkgs.runCommand "firefox-default-profile" {
          buildInputs = [
            pkgs.xvfb-run
            (pkgs.firefox.override {
              extraPolicies = {
                Extensions.Install = map (x: x.src.outPath) addons;
                ExtensionSettings = {
                  "google@search.mozilla.org" = {installation_mode = "blocked";};
                  "amazondotcom@search.mozilla.org" = {installation_mode = "blocked";};
                  "wikipedia@search.mozilla.org" = {installation_mode = "blocked";};
                  "bing@search.mozilla.org" = {installation_mode = "blocked";};
                };
              };
            })
          ];
        } ''
          HOME=$(mktemp -d)
          export FONTCONFIG_FILE=${pkgs.makeFontsConf {fontDirectories = [pkgs.roboto];}}
          mkdir -p $HOME/.mozilla/firefox/
          mkdir $out
          ln -s $out $HOME/.mozilla/firefox/default
          cat >> $HOME/.mozilla/firefox/profiles.ini<< EOF
          [Profile0]
          Default=1
          IsRelative=1
          Name=default
          Path=default
          EOF

          echo user_pref\(\"browser.region.network.url\", \"\"\)\; > $HOME/.mozilla/firefox/default/user.js

          xvfb-run firefox --screenshot about:blank --headless

          # cat $HOME/.mozilla/firefox/default/extensions.json > $out
          #
        '';
      extensionsData = "${firefoxData}/extensions.json";

      # addonStartup = builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile (pkgs.runCommand "addonStartup.json" {
      #   buildInputs = [
      #     pkgs.mozlz4a
      #     pkgs.jq
      #   ];
      # }
      # ''
      # mozlz4a -d ${firefoxData}/addonStartup.json.lz4 /dev/stdout | jq . > $out
      # '')));

      # decrappedAddonStartup = lib.attrsets.updateManyAttrsByPath [
      #   {
      #     path = ["app-builtin" "addons" "google@search.mozilla.org" "enable"];
      #     update = old: false;
      #   }
      # ] addonStartup;

      extensionManifest = e:
        builtins.fromJSON (builtins.readFile (pkgs.runCommand "${e.addonId}-manifest.json" {buildInputs = [pkgs.p7zip];} ''
          7z x -so ${e.src.outPath} manifest.json > $out
        ''));
    in {
      # these come from the HM module
      home.file."${prf}/extension-preferences.json".source = pkgs.emptyFile;
      home.file."${prf}/extension-preferences.json.tmp".source = pkgs.emptyFile;

      home.file."${prf}/extension-settings.json".source = pkgs.emptyFile;
      home.file."${prf}/extension-settings.json.tmp".source = pkgs.emptyFile;

      # home.file."${prf}/search.json.mozlz4".source = pkgs.emptyFile;
      home.file."${prf}/search.json.mozlz4.tmp".source = pkgs.emptyFile;

      home.file."${prf}/extensions".source = lib.mkForce "${pkgs.symlinkJoin {
        name = "extensions";
        paths = addons;
      }}/share/mozilla/${extensionPath}";

      home.file."${prf}/storage".source = pkgs.emptyDirectory;
      home.file."${prf}/crashes".source = pkgs.emptyDirectory;
      home.file."${prf}/datareporting".source = pkgs.emptyDirectory;
      home.file."${prf}/saved-telemetry-pings".source = pkgs.emptyDirectory;

      # home.file."${prf}/addonStartup.json.lz4".source = mozlz4 "addonStartup.json" (lib.attrsets.updateManyAttrsByPath [
      #   {
      #     path = ["app-builtin" "addons" "google@search.mozilla.org" "enable"];
      #     update = old: false;
      #   }
      # ] addonStartup);
      home.file."${prf}/addonStartup.json.lz4".source = pkgs.emptyFile;
      home.file."${prf}/addonStartup.json.lz4.tmp".source = pkgs.emptyFile;

      home.file."${prf}/addons.json".source = pkgs.emptyFile;
      home.file."${prf}/addons.json.tmp".source = pkgs.emptyFile;

      home.file."${prf}/extensions.json".source = extensionsData;
      # home.file."${prf}/extensions.json".text = builtins.toJSON {
      #   schemaVersion = 35;
      #   addons =
      #     map (x: {
      #       active = true;
      #       appDisabled = false;
      #       defaultLocale = {};
      #       embedderDisabled = false;
      #       foreignInstall = true;
      #       hidden = false;
      #       id = x.addonId;
      #       location = "app-profile";
      #       manifestVersion = (extensionManifest x).manifest_version;
      #       optionalPermissions = {
      #         permissions = (extensionManifest x).optional_permissions or [];
      #         origins = (extensionManifest x).optional_permissions or [];
      #       };
      #       path = x.src.outPath;
      #       rootURI = "jar:file://${x.src.outPath}!/";
      #       softDisabled = false;
      #       type = "extension";
      #       userDisabled = false;
      #       userPermissions = {
      #         permissions = (extensionManifest x).permissions or [];
      #         origins = (extensionManifest x).permissions or [];
      #       };
      #       version = (extensionManifest x).version;
      #     })
      #     addons;
      # };
      home.file."${prf}/extensions.json.tmp".source = pkgs.emptyFile;

      # tries to access W_OK it forever
      # home.file."${prf}/prefs.js".source = pkgs.emptyFile;
      # home.file."${prf}/prefs-1.js".source = pkgs.emptyFile;

      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;
            };
            SearchEngines.Default = "DuckDuckGo";
            ExtensionSettings = {
              "google@search.mozilla.org" = {installation_mode = "blocked";};
              "amazondotcom@search.mozilla.org" = {installation_mode = "blocked";};
              "wikipedia@search.mozilla.org" = {installation_mode = "blocked";};
              "bing@search.mozilla.org" = {installation_mode = "blocked";};
            };
          };
        };
        profiles.${profile} = {
          userChrome = builtins.readFile ./userChrome.css;
          search = {
            default = "DuckDuckGo";
            force = true;
          };
          extensions = with firefox-addons; [
            kristofferhagen-nord-theme

            ublock-origin
            clearurls
            privacy-possum
            skip-redirect
            canvasblocker

            sidebery
          ];
          settings = {
            "extensions.activeThemeID" = "{e410fec2-1cbd-4098-9944-e21e708418af}";

            # (try to) hide crap
            "browser.search.hiddenOneOffs" = "Google,Bing,Amazon.com,eBay,Twitter,Wikipedia (en)";
            "browser.newtabpage.activity-stream.showSponsored" = false;
            "browser.newtabpage.activity-stream.showSponsoredTopSites" = false;
            "services.sync.prefs.sync.browser.newtabpage.activity-stream.showSponsored" = false;
            "services.sync.prefs.sync.browser.newtabpage.activity-stream.showSponsoredTopSites" = false;
            "browser.newtabpage.activity-stream.default.sites" = "";
            "browser.urlbar.suggest.topsites" = false;
            "browser.newtabpage.activity-stream.feeds.topsites" = false;

            # disable welcome page
            "browser.aboutwelcome.enabled" = false;
            # disable privacy notice
            "datareporting.policy.firstRunURL" = "";
            # "browser.newtabpage.activity-stream.aboutHome.enabled" = false;
          };
          # extraConfig = {

          # };
        };
      };
    };
  }