1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-14 15:19:45 +01:00
home-manager/modules/programs/chromium.nix

219 lines
7.2 KiB
Nix
Raw Normal View History

2018-05-29 18:41:53 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
supportedBrowsers = [
"chromium"
"google-chrome"
"google-chrome-beta"
"google-chrome-dev"
"brave"
2021-11-17 08:49:28 +01:00
"vivaldi"
];
2018-05-29 18:41:53 +02:00
browserModule = defaultPkg: name: visible:
let
browser = (builtins.parseDrvName defaultPkg.name).name;
isProprietaryChrome = hasPrefix "Google Chrome" name;
2020-02-02 00:39:17 +01:00
in {
enable = mkOption {
inherit visible;
type = types.bool;
2020-02-02 00:39:17 +01:00
default = false;
example = true;
description = "Whether to enable ${name}.";
2020-02-02 00:39:17 +01:00
};
2018-05-29 18:41:53 +02:00
2020-02-02 00:39:17 +01:00
package = mkOption {
inherit visible;
type = types.package;
default = defaultPkg;
defaultText = literalExpression "pkgs.${browser}";
description = "The ${name} package to use.";
2020-02-02 00:39:17 +01:00
};
commandLineArgs = mkOption {
inherit visible;
type = types.listOf types.str;
default = [ ];
example = [ "--enable-logging=stderr" "--ignore-gpu-blocklist" ];
description = ''
List of command-line arguments to be passed to ${name}.
For a list of common switches, see
[Chrome switches](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/chrome_switches.cc).
To search switches for other components, see
[Chromium codesearch](https://source.chromium.org/search?q=file:switches.cc&ss=chromium%2Fchromium%2Fsrc).
'';
};
} // optionalAttrs (!isProprietaryChrome) {
# Extensions do not work with Google Chrome
# see https://github.com/nix-community/home-manager/issues/1383
2020-02-02 00:39:17 +01:00
extensions = mkOption {
inherit visible;
type = with types;
let
extensionType = submodule {
options = {
id = mkOption {
type = strMatching "[a-zA-Z]{32}";
description = ''
2022-12-03 05:20:00 +01:00
The extension's ID from the Chrome Web Store url or the unpacked crx.
'';
default = "";
};
updateUrl = mkOption {
type = str;
description = ''
URL of the extension's update manifest XML file. Linux only.
'';
default = "https://clients2.google.com/service/update2/crx";
visible = pkgs.stdenv.isLinux;
readOnly = pkgs.stdenv.isDarwin;
};
crxPath = mkOption {
type = nullOr path;
description = ''
Path to the extension's crx file. Linux only.
'';
default = null;
visible = pkgs.stdenv.isLinux;
};
version = mkOption {
type = nullOr str;
description = ''
The extension's version, required for local installation. Linux only.
'';
default = null;
visible = pkgs.stdenv.isLinux;
};
};
};
in listOf (coercedTo str (v: { id = v; }) extensionType);
2020-02-02 00:39:17 +01:00
default = [ ];
example = literalExpression ''
2020-02-02 00:39:17 +01:00
[
{ id = "cjpalhdlnbpafiamejdnhcphjbkeiagm"; } # ublock origin
{
id = "dcpihecpambacapedldabdbpakmachpb";
updateUrl = "https://raw.githubusercontent.com/iamadamdev/bypass-paywalls-chrome/master/updates.xml";
}
{
id = "aaaaaaaaaabbbbbbbbbbcccccccccc";
crxPath = "/home/share/extension.crx";
version = "1.0";
}
2020-02-02 00:39:17 +01:00
]
'';
description = ''
2020-02-02 00:39:17 +01:00
List of ${name} extensions to install.
To find the extension ID, check its URL on the
[Chrome Web Store](https://chrome.google.com/webstore/category/extensions).
To install extensions outside of the Chrome Web Store set
`updateUrl` or `crxPath` and
`version` as explained in the
[Chrome
documentation](https://developer.chrome.com/docs/extensions/mv2/external_extensions).
2020-02-02 00:39:17 +01:00
'';
2018-05-29 18:41:53 +02:00
};
dictionaries = mkOption {
inherit visible;
type = types.listOf types.package;
default = [ ];
example = literalExpression ''
[
pkgs.hunspellDictsChromium.en_US
]
'';
description = ''
List of ${name} dictionaries to install.
'';
};
2020-02-02 00:39:17 +01:00
};
2018-05-29 18:41:53 +02:00
browserConfig = cfg:
let
drvName = (builtins.parseDrvName cfg.package.name).name;
browser = if drvName == "ungoogled-chromium" then "chromium" else drvName;
isProprietaryChrome = hasPrefix "google-chrome" drvName;
2018-05-29 18:41:53 +02:00
darwinDirs = {
chromium = "Chromium";
google-chrome = "Google/Chrome";
google-chrome-beta = "Google/Chrome Beta";
google-chrome-dev = "Google/Chrome Dev";
brave = "BraveSoftware/Brave-Browser";
2018-05-29 18:41:53 +02:00
};
linuxDirs = { brave = "BraveSoftware/Brave-Browser"; };
2020-02-02 00:39:17 +01:00
configDir = if pkgs.stdenv.isDarwin then
"Library/Application Support/" + (darwinDirs."${browser}" or browser)
2020-02-02 00:39:17 +01:00
else
"${config.xdg.configHome}/" + (linuxDirs."${browser}" or browser);
2018-05-29 18:41:53 +02:00
extensionJson = ext:
assert ext.crxPath != null -> ext.version != null;
with builtins; {
name = "${configDir}/External Extensions/${ext.id}.json";
value.text = toJSON (if ext.crxPath != null then {
external_crx = ext.crxPath;
external_version = ext.version;
} else {
external_update_url = ext.updateUrl;
});
2018-05-29 18:41:53 +02:00
};
dictionary = pkg: {
name = "${configDir}/Dictionaries/${pkg.passthru.dictFileName}";
value.source = pkg;
};
package = if cfg.commandLineArgs != [ ] then
cfg.package.override {
commandLineArgs = concatStringsSep " " cfg.commandLineArgs;
}
else
cfg.package;
2020-02-02 00:39:17 +01:00
in mkIf cfg.enable {
home.packages = [ package ];
home.file = optionalAttrs (!isProprietaryChrome) (listToAttrs
((map extensionJson cfg.extensions)
++ (map dictionary cfg.dictionaries)));
2020-02-02 00:39:17 +01:00
};
2018-05-29 18:41:53 +02:00
2020-02-02 00:39:17 +01:00
in {
# Extensions do not work with the proprietary Google Chrome version
# see https://github.com/nix-community/home-manager/issues/1383
imports = map (flip mkRemovedOptionModule
"The `extensions` option does not work on Google Chrome anymore.") [
[ "programs" "google-chrome" "extensions" ]
[ "programs" "google-chrome-beta" "extensions" ]
[ "programs" "google-chrome-dev" "extensions" ]
];
2018-05-29 18:41:53 +02:00
options.programs = {
chromium = browserModule pkgs.chromium "Chromium" true;
google-chrome = browserModule pkgs.google-chrome "Google Chrome" false;
2020-02-02 00:39:17 +01:00
google-chrome-beta =
browserModule pkgs.google-chrome-beta "Google Chrome Beta" false;
2020-02-02 00:39:17 +01:00
google-chrome-dev =
browserModule pkgs.google-chrome-dev "Google Chrome Dev" false;
brave = browserModule pkgs.brave "Brave Browser" false;
vivaldi = browserModule pkgs.vivaldi "Vivaldi Browser" false;
2018-05-29 18:41:53 +02:00
};
config = mkMerge
(map (browser: browserConfig config.programs.${browser}) supportedBrowsers);
2018-05-29 18:41:53 +02:00
}