1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.programs.chromium;
10
11 defaultProfile = lib.filterAttrs (k: v: v != null) {
12 HomepageLocation = cfg.homepageLocation;
13 DefaultSearchProviderEnabled = cfg.defaultSearchProviderEnabled;
14 DefaultSearchProviderSearchURL = cfg.defaultSearchProviderSearchURL;
15 DefaultSearchProviderSuggestURL = cfg.defaultSearchProviderSuggestURL;
16 ExtensionInstallForcelist = cfg.extensions;
17 };
18in
19
20{
21 ###### interface
22
23 options = {
24 programs.chromium = {
25 enable = lib.mkEnableOption "policies for chromium based browsers like Chromium, Google Chrome or Brave";
26
27 enablePlasmaBrowserIntegration = lib.mkEnableOption "Native Messaging Host for Plasma Browser Integration";
28
29 plasmaBrowserIntegrationPackage = lib.mkPackageOption pkgs [
30 "kdePackages"
31 "plasma-browser-integration"
32 ] { };
33
34 extensions = lib.mkOption {
35 type = with lib.types; nullOr (listOf str);
36 description = ''
37 List of chromium extensions to install.
38 For list of plugins ids see id in url of extensions on
39 [chrome web store](https://chrome.google.com/webstore/category/extensions)
40 page. To install a chromium extension not included in the chrome web
41 store, append to the extension id a semicolon ";" followed by a URL
42 pointing to an Update Manifest XML file. See
43 [ExtensionInstallForcelist](https://cloud.google.com/docs/chrome-enterprise/policies/?policy=ExtensionInstallForcelist)
44 for additional details.
45 '';
46 default = null;
47 example = lib.literalExpression ''
48 [
49 "chlffgpmiacpedhhbkiomidkjlcfhogd" # pushbullet
50 "mbniclmhobmnbdlbpiphghaielnnpgdp" # lightshot
51 "gcbommkclmclpchllfjekcdonpmejbdp" # https everywhere
52 "cjpalhdlnbpafiamejdnhcphjbkeiagm" # ublock origin
53 ]
54 '';
55 };
56
57 homepageLocation = lib.mkOption {
58 type = lib.types.nullOr lib.types.str;
59 description = "Chromium default homepage";
60 default = null;
61 example = "https://nixos.org";
62 };
63
64 defaultSearchProviderEnabled = lib.mkOption {
65 type = lib.types.nullOr lib.types.bool;
66 description = "Enable the default search provider.";
67 default = null;
68 example = true;
69 };
70
71 defaultSearchProviderSearchURL = lib.mkOption {
72 type = lib.types.nullOr lib.types.str;
73 description = "Chromium default search provider url.";
74 default = null;
75 example = "https://encrypted.google.com/search?q={searchTerms}&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}ie={inputEncoding}";
76 };
77
78 defaultSearchProviderSuggestURL = lib.mkOption {
79 type = lib.types.nullOr lib.types.str;
80 description = "Chromium default search provider url for suggestions.";
81 default = null;
82 example = "https://encrypted.google.com/complete/search?output=chrome&q={searchTerms}";
83 };
84
85 extraOpts = lib.mkOption {
86 type = lib.types.attrs;
87 description = ''
88 Extra chromium policy options. A list of available policies
89 can be found in the Chrome Enterprise documentation:
90 <https://cloud.google.com/docs/chrome-enterprise/policies/>
91 Make sure the selected policy is supported on Linux and your browser version.
92 '';
93 default = { };
94 example = lib.literalExpression ''
95 {
96 "BrowserSignin" = 0;
97 "SyncDisabled" = true;
98 "PasswordManagerEnabled" = false;
99 "SpellcheckEnabled" = true;
100 "SpellcheckLanguage" = [
101 "de"
102 "en-US"
103 ];
104 }
105 '';
106 };
107
108 initialPrefs = lib.mkOption {
109 type = lib.types.attrs;
110 description = ''
111 Initial preferences are used to configure the browser for the first run.
112 Unlike {option}`programs.chromium.extraOpts`, initialPrefs can be changed by users in the browser settings.
113 More information can be found in the Chromium documentation:
114 <https://www.chromium.org/administrators/configuring-other-preferences/>
115 '';
116 default = { };
117 example = lib.literalExpression ''
118 {
119 "first_run_tabs" = [
120 "https://nixos.org/"
121 ];
122 }
123 '';
124 };
125 };
126 };
127
128 ###### implementation
129
130 config = {
131 environment.etc = lib.mkIf cfg.enable {
132 # for chromium
133 "chromium/native-messaging-hosts/org.kde.plasma.browser_integration.json" =
134 lib.mkIf cfg.enablePlasmaBrowserIntegration
135 {
136 source = "${cfg.plasmaBrowserIntegrationPackage}/etc/chromium/native-messaging-hosts/org.kde.plasma.browser_integration.json";
137 };
138 "chromium/policies/managed/default.json" = lib.mkIf (defaultProfile != { }) {
139 text = builtins.toJSON defaultProfile;
140 };
141 "chromium/policies/managed/extra.json" = lib.mkIf (cfg.extraOpts != { }) {
142 text = builtins.toJSON cfg.extraOpts;
143 };
144 "chromium/initial_preferences" = lib.mkIf (cfg.initialPrefs != { }) {
145 text = builtins.toJSON cfg.initialPrefs;
146 };
147 # for google-chrome https://www.chromium.org/administrators/linux-quick-start
148 "opt/chrome/native-messaging-hosts/org.kde.plasma.browser_integration.json" =
149 lib.mkIf cfg.enablePlasmaBrowserIntegration
150 {
151 source = "${cfg.plasmaBrowserIntegrationPackage}/etc/opt/chrome/native-messaging-hosts/org.kde.plasma.browser_integration.json";
152 };
153 "opt/chrome/policies/managed/default.json" = lib.mkIf (defaultProfile != { }) {
154 text = builtins.toJSON defaultProfile;
155 };
156 "opt/chrome/policies/managed/extra.json" = lib.mkIf (cfg.extraOpts != { }) {
157 text = builtins.toJSON cfg.extraOpts;
158 };
159 # for brave
160 "brave/policies/managed/default.json" = lib.mkIf (defaultProfile != { }) {
161 text = builtins.toJSON defaultProfile;
162 };
163 "brave/policies/managed/extra.json" = lib.mkIf (cfg.extraOpts != { }) {
164 text = builtins.toJSON cfg.extraOpts;
165 };
166 };
167 };
168}