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

  options.web.chromium = {
    enable = lib.mkEnableOption "Enables chromium.";
    package = lib.mkOption {
      type = lib.types.package;
      readOnly = true;
      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 {
    programs.chromium = {
      enable = true;
      package = pkgs.ungoogled-chromium;
      commandLineArgs =
        let
          extensionDirs = lib.concatStringsSep "," (
            lib.mapAttrsToList (_: ext: ext.drv) config.web.chromium.extensions
          );
        in
        [
          "--force-device-scale-factor=1.15"
          "--load-extension=${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 {
        NewTabPage = {
          FooterVisible = false;
        };
        bookmark_bar = {
          show_on_all_tabs = false;
        };
        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 = [
            config.web.chromium.extensions.browserpass.id
            config.web.chromium.extensions.darkreader.id
            config.web.chromium.extensions.ublockOrigin.id
          ];
          ui = {
            developer_mode = true;
          };
        };
        profile = {
          default_content_setting_values = {
            notifications = 2;
          };
        };
        high_efficiency_mode_enabled = true;
      };
    };
  };
}