summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/google-chrome.nix
blob: acc298b56cf7ad23e1059ae831c550c1995f6bb3 (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
{
  config,
  lib,
  pkgs,
  ...
}:

let
  cfg = config.programs.google-chrome;
in
{
  options.programs.google-chrome = {
    enable = lib.mkEnableOption "Google Chrome browser";
    package = lib.mkPackageOption pkgs "google-chrome" { };

    extensions = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [ ];
      example = [
        "cjpalhdlnbpafiamejdnhcphjbkeiagm" # uBlock Origin
        "nngceckbapebfimnlniiiahkandclblb" # Bitwarden
      ];
      description = "List of Chrome extension IDs to force install.";
    };

    commandLineArgs = lib.mkOption {
      type = lib.types.listOf lib.types.str;
      default = [ ];
      example = [
        "--disable-gpu"
        "--enable-features=VaapiVideoDecoder"
      ];
      description = "Extra command line arguments passed to Google Chrome.";
    };

    policies = lib.mkOption {
      type = lib.types.attrs;
      default = { };
      example = {
        HomepageLocation = "https://nixos.org";
        PasswordManagerEnabled = false;
      };
      description = "Chrome enterprise policies written to managed policies JSON.";
    };
  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = [
      (cfg.package.override {
        commandLineArgs = cfg.commandLineArgs;
      })
    ];

    environment.etc."opt/chrome/policies/managed/nixos.json".text =
      let
        extensionList = map (id: "${id};https://clients2.google.com/service/update2/crx") cfg.extensions;

        finalPolicies = lib.recursiveUpdate cfg.policies (
          lib.optionalAttrs (cfg.extensions != [ ]) {
            ExtensionInstallForcelist = extensionList;
          }
        );
      in
      builtins.toJSON finalPolicies;

    environment.sessionVariables.GOOGLE_CHROME_EXTRA_ARGS = lib.concatStringsSep " " cfg.commandLineArgs;
  };
}