2018-05-29 16:41:53 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
browserModule = defaultPkg: name: visible:
|
2021-03-18 00:47:00 +00:00
|
|
|
let
|
|
|
|
browser = (builtins.parseDrvName defaultPkg.name).name;
|
|
|
|
isProprietaryChrome = hasPrefix "Google Chrome" name;
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
|
|
|
enable = mkOption {
|
|
|
|
inherit visible;
|
|
|
|
default = false;
|
|
|
|
example = true;
|
|
|
|
description = "Whether to enable ${name}.";
|
|
|
|
type = lib.types.bool;
|
|
|
|
};
|
2018-05-29 16:41:53 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
package = mkOption {
|
|
|
|
inherit visible;
|
|
|
|
type = types.package;
|
|
|
|
default = defaultPkg;
|
|
|
|
defaultText = literalExample "pkgs.${browser}";
|
|
|
|
description = "The ${name} package to use.";
|
|
|
|
};
|
2021-03-18 00:47:00 +00:00
|
|
|
} // optionalAttrs (!isProprietaryChrome) {
|
|
|
|
# Extensions do not work with Google Chrome
|
|
|
|
# see https://github.com/nix-community/home-manager/issues/1383
|
2020-02-01 23:39:17 +00:00
|
|
|
extensions = mkOption {
|
|
|
|
inherit visible;
|
2020-12-08 20:19:22 +00:00
|
|
|
type = with types;
|
|
|
|
let
|
|
|
|
extensionType = submodule {
|
|
|
|
options = {
|
|
|
|
id = mkOption {
|
|
|
|
type = strMatching "[a-zA-Z]{32}";
|
|
|
|
description = ''
|
|
|
|
The extension's ID from the Chome 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-01 23:39:17 +00:00
|
|
|
default = [ ];
|
|
|
|
example = literalExample ''
|
|
|
|
[
|
2020-12-08 20:19:22 +00: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-01 23:39:17 +00:00
|
|
|
]
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
List of ${name} extensions to install.
|
|
|
|
To find the extension ID, check its URL on the
|
|
|
|
<link xlink:href="https://chrome.google.com/webstore/category/extensions">Chrome Web Store</link>.
|
2020-12-08 20:19:22 +00:00
|
|
|
</para><para>
|
|
|
|
To install extensions outside of the Chrome Web Store set
|
|
|
|
<literal>updateUrl</literal> or <literal>crxPath</literal> and
|
|
|
|
<literal>version</literal> as explained in the
|
|
|
|
<link xlink:href="https://developer.chrome.com/docs/extensions/mv2/external_extensions">Chrome
|
|
|
|
documentation</link>.
|
2020-02-01 23:39:17 +00:00
|
|
|
'';
|
2018-05-29 16:41:53 +00:00
|
|
|
};
|
2020-02-01 23:39:17 +00:00
|
|
|
};
|
2018-05-29 16:41:53 +00:00
|
|
|
|
|
|
|
browserConfig = cfg:
|
|
|
|
let
|
|
|
|
|
2021-01-19 07:50:01 +00:00
|
|
|
drvName = (builtins.parseDrvName cfg.package.name).name;
|
|
|
|
browser = if drvName == "ungoogled-chromium" then "chromium" else drvName;
|
2018-05-29 16:41:53 +00:00
|
|
|
|
|
|
|
darwinDirs = {
|
|
|
|
chromium = "Chromium";
|
|
|
|
google-chrome = "Google/Chrome";
|
|
|
|
google-chrome-beta = "Google/Chrome Beta";
|
|
|
|
google-chrome-dev = "Google/Chrome Dev";
|
2020-11-27 04:38:17 +00:00
|
|
|
brave = "BraveSoftware/Brave-Browser";
|
2018-05-29 16:41:53 +00:00
|
|
|
};
|
|
|
|
|
2021-07-12 01:19:10 +00:00
|
|
|
linuxDirs = { brave = "BraveSoftware/Brave-Browser"; };
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
configDir = if pkgs.stdenv.isDarwin then
|
2021-07-12 01:19:10 +00:00
|
|
|
"Library/Application Support/" + (darwinDirs."${browser}" or browser)
|
2020-02-01 23:39:17 +00:00
|
|
|
else
|
2021-07-12 01:19:10 +00:00
|
|
|
"${config.xdg.configHome}/" + (linuxDirs."${browser}" or browser);
|
2018-05-29 16:41:53 +00:00
|
|
|
|
2020-12-08 20:19:22 +00:00
|
|
|
extensionJson = ext:
|
2021-01-18 22:15:34 +00:00
|
|
|
assert ext.crxPath != null -> ext.version != null;
|
2020-12-08 20:19:22 +00:00
|
|
|
with builtins; {
|
|
|
|
name = "${configDir}/External Extensions/${ext.id}.json";
|
2021-01-18 22:15:34 +00:00
|
|
|
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 16:41:53 +00:00
|
|
|
};
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in mkIf cfg.enable {
|
|
|
|
home.packages = [ cfg.package ];
|
2021-03-18 00:47:00 +00:00
|
|
|
home.file = listToAttrs (map extensionJson (cfg.extensions or [ ]));
|
2020-02-01 23:39:17 +00:00
|
|
|
};
|
2018-05-29 16:41:53 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2021-03-18 00:47:00 +00:00
|
|
|
# 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 16:41:53 +00:00
|
|
|
options.programs = {
|
|
|
|
chromium = browserModule pkgs.chromium "Chromium" true;
|
|
|
|
google-chrome = browserModule pkgs.google-chrome "Google Chrome" false;
|
2020-02-01 23:39:17 +00:00
|
|
|
google-chrome-beta =
|
|
|
|
browserModule pkgs.google-chrome-beta "Google Chrome Beta" false;
|
|
|
|
google-chrome-dev =
|
|
|
|
browserModule pkgs.google-chrome-dev "Google Chrome Dev" false;
|
2020-11-27 04:38:17 +00:00
|
|
|
brave = browserModule pkgs.brave "Brave Browser" false;
|
2018-05-29 16:41:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkMerge [
|
|
|
|
(browserConfig config.programs.chromium)
|
|
|
|
(browserConfig config.programs.google-chrome)
|
|
|
|
(browserConfig config.programs.google-chrome-beta)
|
|
|
|
(browserConfig config.programs.google-chrome-dev)
|
2020-11-27 04:38:17 +00:00
|
|
|
(browserConfig config.programs.brave)
|
2018-05-29 16:41:53 +00:00
|
|
|
];
|
|
|
|
}
|