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