at 23.11-pre 4.5 kB view raw
1{ config, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.programs.chromium; 7 8 defaultProfile = filterAttrs (k: v: v != null) { 9 HomepageLocation = cfg.homepageLocation; 10 DefaultSearchProviderEnabled = cfg.defaultSearchProviderEnabled; 11 DefaultSearchProviderSearchURL = cfg.defaultSearchProviderSearchURL; 12 DefaultSearchProviderSuggestURL = cfg.defaultSearchProviderSuggestURL; 13 ExtensionInstallForcelist = cfg.extensions; 14 }; 15in 16 17{ 18 ###### interface 19 20 options = { 21 programs.chromium = { 22 enable = mkEnableOption (lib.mdDoc "{command}`chromium` policies"); 23 24 extensions = mkOption { 25 type = types.listOf types.str; 26 description = lib.mdDoc '' 27 List of chromium extensions to install. 28 For list of plugins ids see id in url of extensions on 29 [chrome web store](https://chrome.google.com/webstore/category/extensions) 30 page. To install a chromium extension not included in the chrome web 31 store, append to the extension id a semicolon ";" followed by a URL 32 pointing to an Update Manifest XML file. See 33 [ExtensionInstallForcelist](https://cloud.google.com/docs/chrome-enterprise/policies/?policy=ExtensionInstallForcelist) 34 for additional details. 35 ''; 36 default = []; 37 example = literalExpression '' 38 [ 39 "chlffgpmiacpedhhbkiomidkjlcfhogd" # pushbullet 40 "mbniclmhobmnbdlbpiphghaielnnpgdp" # lightshot 41 "gcbommkclmclpchllfjekcdonpmejbdp" # https everywhere 42 "cjpalhdlnbpafiamejdnhcphjbkeiagm" # ublock origin 43 ] 44 ''; 45 }; 46 47 homepageLocation = mkOption { 48 type = types.nullOr types.str; 49 description = lib.mdDoc "Chromium default homepage"; 50 default = null; 51 example = "https://nixos.org"; 52 }; 53 54 defaultSearchProviderEnabled = mkOption { 55 type = types.nullOr types.bool; 56 description = lib.mdDoc "Enable the default search provider."; 57 default = null; 58 example = true; 59 }; 60 61 defaultSearchProviderSearchURL = mkOption { 62 type = types.nullOr types.str; 63 description = lib.mdDoc "Chromium default search provider url."; 64 default = null; 65 example = 66 "https://encrypted.google.com/search?q={searchTerms}&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}ie={inputEncoding}"; 67 }; 68 69 defaultSearchProviderSuggestURL = mkOption { 70 type = types.nullOr types.str; 71 description = lib.mdDoc "Chromium default search provider url for suggestions."; 72 default = null; 73 example = 74 "https://encrypted.google.com/complete/search?output=chrome&q={searchTerms}"; 75 }; 76 77 extraOpts = mkOption { 78 type = types.attrs; 79 description = lib.mdDoc '' 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 = 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 }; 101 102 ###### implementation 103 104 config = lib.mkIf cfg.enable { 105 # for chromium 106 environment.etc."chromium/policies/managed/default.json".text = builtins.toJSON defaultProfile; 107 environment.etc."chromium/policies/managed/extra.json".text = builtins.toJSON cfg.extraOpts; 108 # for google-chrome https://www.chromium.org/administrators/linux-quick-start 109 environment.etc."opt/chrome/policies/managed/default.json".text = builtins.toJSON defaultProfile; 110 environment.etc."opt/chrome/policies/managed/extra.json".text = builtins.toJSON cfg.extraOpts; 111 # for brave 112 environment.etc."brave/policies/managed/default.json".text = builtins.toJSON defaultProfile; 113 environment.etc."brave/policies/managed/extra.json".text = builtins.toJSON cfg.extraOpts; 114 }; 115}