fork/home-manager
git clone https://git.julia.blue/fork/home-manager
f8c5fd75
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7supportedBrowsers = [ 8"chromium" 9"google-chrome" 10"google-chrome-beta" 11"google-chrome-dev" 12"brave" 13"vivaldi" 14]; 15 16browserModule = defaultPkg :name :visible : 17let 18browser = ( builtins . parseDrvName defaultPkg . name ). name ; 19isProprietaryChrome = hasPrefix "Google Chrome" name ; 20in { 21enable = mkOption { 22inherit visible ; 23type = types . bool ; 24default = false ; 25example = true ; 26description = "Whether to enable ${ name } ." ; 27}; 28 29package = mkOption { 30inherit visible ; 31type = types . package ; 32default = defaultPkg ; 33defaultText = literalExpression "pkgs. ${ browser } " ; 34description = "The ${ name } package to use." ; 35}; 36 37commandLineArgs = mkOption { 38inherit visible ; 39type = types . listOf types . str ; 40default = [ ]; 41example = [ "--enable-logging=stderr" "--ignore-gpu-blocklist" ]; 42description = '' 43List of command-line arguments to be passed to ${ name } . 44 45For a list of common switches, see 46[Chrome switches](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/chrome_switches.cc). 47 48To search switches for other components, see 49[Chromium codesearch](https://source.chromium.org/search?q=file:switches.cc&ss=chromium%2Fchromium%2Fsrc). 50'' ; 51}; 52} // optionalAttrs ( ! isProprietaryChrome ) { 53# Extensions do not work with Google Chrome 54# see https://github.com/nix-community/home-manager/issues/1383 55extensions = mkOption { 56inherit visible ; 57type = with types ; 58let 59extensionType = submodule { 60options = { 61id = mkOption { 62type = strMatching "[a-zA-Z]{32}" ; 63description = '' 64The extension's ID from the Chrome Web Store url or the unpacked crx. 65'' ; 66default = "" ; 67}; 68 69updateUrl = mkOption { 70type = str ; 71description = '' 72URL of the extension's update manifest XML file. Linux only. 73'' ; 74default = "https://clients2.google.com/service/update2/crx" ; 75visible = pkgs . stdenv . isLinux ; 76readOnly = pkgs . stdenv . isDarwin ; 77}; 78 79crxPath = mkOption { 80type = nullOr path ; 81description = '' 82Path to the extension's crx file. Linux only. 83'' ; 84default = null ; 85visible = pkgs . stdenv . isLinux ; 86}; 87 88version = mkOption { 89type = nullOr str ; 90description = '' 91The extension's version, required for local installation. Linux only. 92'' ; 93default = null ; 94visible = pkgs . stdenv . isLinux ; 95}; 96}; 97}; 98in listOf ( coercedTo str ( v :{ id = v ; }) extensionType ); 99default = [ ]; 100example = literalExpression '' 101[ 102{ id = "cjpalhdlnbpafiamejdnhcphjbkeiagm"; } # ublock origin 103{ 104id = "dcpihecpambacapedldabdbpakmachpb"; 105updateUrl = "https://raw.githubusercontent.com/iamadamdev/bypass-paywalls-chrome/master/updates.xml"; 106} 107{ 108id = "aaaaaaaaaabbbbbbbbbbcccccccccc"; 109crxPath = "/home/share/extension.crx"; 110version = "1.0"; 111} 112] 113'' ; 114description = '' 115List of ${ name } extensions to install. 116To find the extension ID, check its URL on the 117[Chrome Web Store](https://chrome.google.com/webstore/category/extensions). 118 119To install extensions outside of the Chrome Web Store set 120`updateUrl` or `crxPath` and 121`version` as explained in the 122[Chrome 123documentation](https://developer.chrome.com/docs/extensions/mv2/external_extensions). 124'' ; 125}; 126 127dictionaries = mkOption { 128inherit visible ; 129type = types . listOf types . package ; 130default = [ ]; 131example = literalExpression '' 132[ 133pkgs.hunspellDictsChromium.en_US 134] 135'' ; 136description = '' 137List of ${ name } dictionaries to install. 138'' ; 139}; 140}; 141 142browserConfig = cfg : 143let 144 145drvName = ( builtins . parseDrvName cfg . package . name ). name ; 146browser = if drvName == "ungoogled-chromium" then "chromium" else drvName ; 147isProprietaryChrome = hasPrefix "google-chrome" drvName ; 148 149darwinDirs = { 150chromium = "Chromium" ; 151google-chrome = "Google/Chrome" ; 152google-chrome-beta = "Google/Chrome Beta" ; 153google-chrome-dev = "Google/Chrome Dev" ; 154brave = "BraveSoftware/Brave-Browser" ; 155}; 156 157linuxDirs = { brave = "BraveSoftware/Brave-Browser" ; }; 158 159configDir = if pkgs . stdenv . isDarwin then 160"Library/Application Support/" + ( darwinDirs . " ${ browser } " or browser ) 161else 162" ${ config . xdg . configHome } /" + ( linuxDirs . " ${ browser } " or browser ); 163 164extensionJson = ext : 165assert ext . crxPath != null -> ext . version != null ; 166with builtins ; { 167name = " ${ configDir } /External Extensions/ ${ ext . id } .json" ; 168value . text = toJSON ( if ext . crxPath != null then { 169external_crx = ext . crxPath ; 170external_version = ext . version ; 171} else { 172external_update_url = ext . updateUrl ; 173}); 174}; 175 176dictionary = pkg :{ 177name = " ${ configDir } /Dictionaries/ ${ pkg . passthru . dictFileName } " ; 178value . source = pkg ; 179}; 180 181package = if cfg . commandLineArgs != [ ] then 182cfg . package . override { 183commandLineArgs = concatStringsSep " " cfg . commandLineArgs ; 184} 185else 186cfg . package ; 187 188in mkIf cfg . enable { 189home . packages = [ package ]; 190home . file = optionalAttrs ( ! isProprietaryChrome ) ( listToAttrs 191(( map extensionJson cfg . extensions ) 192++ ( map dictionary cfg . dictionaries ))); 193}; 194 195in { 196# Extensions do not work with the proprietary Google Chrome version 197# see https://github.com/nix-community/home-manager/issues/1383 198imports = map ( flip mkRemovedOptionModule 199"The `extensions` option does not work on Google Chrome anymore." ) [ 200[ "programs" "google-chrome" "extensions" ] 201[ "programs" "google-chrome-beta" "extensions" ] 202[ "programs" "google-chrome-dev" "extensions" ] 203]; 204 205options . programs = { 206chromium = browserModule pkgs . chromium "Chromium" true ; 207google-chrome = browserModule pkgs . google-chrome "Google Chrome" false ; 208google-chrome-beta = 209browserModule pkgs . google-chrome-beta "Google Chrome Beta" false ; 210google-chrome-dev = 211browserModule pkgs . google-chrome-dev "Google Chrome Dev" false ; 212brave = browserModule pkgs . brave "Brave Browser" false ; 213vivaldi = browserModule pkgs . vivaldi "Vivaldi Browser" false ; 214}; 215 216config = mkMerge 217( map ( browser :browserConfig config . programs .${ browser }) supportedBrowsers ); 218}