aboutsummaryrefslogtreecommitdiffstats
path: root/modules/web/chromium/default.nix
blob: 8cf0beacd2b8c204ecdd4ae5e47f873e8d3b9aa5 (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
{
  config,
  lib,
  pkgs,
  ...
}:
{
  imports = [
    ./browserpass.nix
  ];

  options.web.chromium = {
    enable = lib.mkEnableOption "Enables chromium.";
    package = lib.mkOption {
      type = lib.types.package;
      default = config.programs.chromium.finalPackage;
      defaultText = lib.literalExpression "config.programs.chromium.finalPackage";
      description = "Package to use for chromium. Defaults to the wrapped finalPackage from programs.chromium.";
    };
    checkForUpdates = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = ''
        Check GitHub for newer extension releases before building, and abort
        with upgrade instructions if the pinned version is stale. Requires
        network access during evaluation (pass --impure to nix/home-manager).
      '';
    };
  };

  config = lib.mkIf config.web.chromium.enable (
    let
      exts = import ./extensions {
        inherit lib pkgs;
        checkForUpdates = config.web.chromium.checkForUpdates;
      };

      extensionDirs = [
        exts.ublockOrigin.drv
        exts.darkMode.drv
        exts.browserpass.drv
        exts.aria2Explorer.drv
      ];

      pinnedIds = lib.filter (id: id != null) [
        exts.browserpass.id
        exts.darkMode.id
        exts.ublockOrigin.id
      ];
    in
    {
      programs.chromium = {
        enable = true;
        package = pkgs.ungoogled-chromium;
        commandLineArgs = [
          "--force-device-scale-factor=1.15"
          "--load-extension=${lib.concatStringsSep "," extensionDirs}"
        ];
      };

      xdg.mimeApps.defaultApplications = {
        "x-scheme-handler/http" = "chromium-browser.desktop";
        "x-scheme-handler/https" = "chromium-browser.desktop";
        "x-scheme-handler/chrome" = "chromium-browser.desktop";
        "text/html" = "chromium-browser.desktop";
        "application/xhtml+xml" = "chromium-browser.desktop";
      };

      xdg.configFile."chromium/Default/Preferences" = {
        force = true;
        text = builtins.toJSON {
          browser = {
            show_full_urls = true;
            theme = {
              follows_system_colors = true;
            };
          };
          search = {
            suggest_enabled = false;
          };
          url_handling = {
            show_full_urls = true;
          };
          autofill = {
            profile_enabled = false;
            credit_card_enabled = false;
          };
          vertical_tabs = {
            collapsed_state = true;
            enabled = true;
            enabled_first_time = true;
            uncollapsed_width = 240;
          };
          credentials_enable_service = false;
          credentials_enable_autosignin = false;
          extensions = {
            pinned_extensions = pinnedIds;
            ui = {
              developer_mode = true;
            };
          };
          profile = {
            default_content_setting_values = {
              notifications = 2;
            };
          };
          high_efficiency_mode_enabled = true;
        };
      };
    }
  );
}