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

93 lines
2.7 KiB
Nix
Raw Normal View History

2018-05-29 18:41:53 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
browserModule = defaultPkg: name: visible:
2020-02-02 00:39:17 +01:00
let browser = (builtins.parseDrvName defaultPkg.name).name;
in {
enable = mkOption {
inherit visible;
default = false;
example = true;
description = "Whether to enable ${name}.";
type = lib.types.bool;
};
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 = literalExample "pkgs.${browser}";
description = "The ${name} package to use.";
};
2018-05-29 18:41:53 +02:00
2020-02-02 00:39:17 +01:00
extensions = mkOption {
inherit visible;
type = types.listOf types.str;
default = [ ];
example = literalExample ''
[
"chlffgpmiacpedhhbkiomidkjlcfhogd" # pushbullet
"mbniclmhobmnbdlbpiphghaielnnpgdp" # lightshot
"gcbommkclmclpchllfjekcdonpmejbdp" # https everywhere
"cjpalhdlnbpafiamejdnhcphjbkeiagm" # ublock origin
]
'';
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>.
'';
2018-05-29 18:41:53 +02:00
};
2020-02-02 00:39:17 +01:00
};
2018-05-29 18:41:53 +02:00
browserConfig = cfg:
let
2018-08-22 19:27:04 +02:00
browser = (builtins.parseDrvName cfg.package.name).name;
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";
};
2020-02-02 00:39:17 +01:00
configDir = if pkgs.stdenv.isDarwin then
"Library/Application Support/${getAttr browser darwinDirs}"
else
"${config.xdg.configHome}/${browser}";
2018-05-29 18:41:53 +02:00
extensionJson = ext: {
name = "${configDir}/External Extensions/${ext}.json";
value.text = builtins.toJSON {
2020-02-02 00:39:17 +01:00
external_update_url =
"https://clients2.google.com/service/update2/crx";
2018-05-29 18:41:53 +02:00
};
};
2020-02-02 00:39:17 +01:00
in mkIf cfg.enable {
home.packages = [ cfg.package ];
home.file = listToAttrs (map extensionJson cfg.extensions);
};
2018-05-29 18:41:53 +02:00
2020-02-02 00:39:17 +01:00
in {
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;
google-chrome-dev =
browserModule pkgs.google-chrome-dev "Google Chrome Dev" false;
2018-05-29 18:41:53 +02:00
};
config = mkMerge [
(browserConfig config.programs.chromium)
(browserConfig config.programs.google-chrome)
(browserConfig config.programs.google-chrome-beta)
(browserConfig config.programs.google-chrome-dev)
];
}