From 3627ec4de58d7fbda13c82dfec94eace10198f23 Mon Sep 17 00:00:00 2001 From: Sebastien Waegeneire Date: Tue, 8 Dec 2020 21:19:22 +0100 Subject: [PATCH] chromium: add support for external extensions This allows the installation of external (outside of the Chrome Web Store) extensions, both local and remote. PR #1648 --- modules/programs/chromium.nix | 79 ++++++++++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/modules/programs/chromium.nix b/modules/programs/chromium.nix index c0017bf70..b97426d02 100644 --- a/modules/programs/chromium.nix +++ b/modules/programs/chromium.nix @@ -25,20 +25,73 @@ let extensions = mkOption { inherit visible; - type = types.listOf types.str; + 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); default = [ ]; example = literalExample '' [ - "chlffgpmiacpedhhbkiomidkjlcfhogd" # pushbullet - "mbniclmhobmnbdlbpiphghaielnnpgdp" # lightshot - "gcbommkclmclpchllfjekcdonpmejbdp" # https everywhere - "cjpalhdlnbpafiamejdnhcphjbkeiagm" # ublock origin + { 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"; + } ] ''; description = '' List of ${name} extensions to install. To find the extension ID, check its URL on the Chrome Web Store. + + To install extensions outside of the Chrome Web Store set + updateUrl or crxPath and + version as explained in the + Chrome + documentation. ''; }; }; @@ -61,13 +114,17 @@ let else "${config.xdg.configHome}/${browser}"; - extensionJson = ext: { - name = "${configDir}/External Extensions/${ext}.json"; - value.text = builtins.toJSON { - external_update_url = - "https://clients2.google.com/service/update2/crx"; + extensionJson = ext: + with builtins; { + name = "${configDir}/External Extensions/${ext.id}.json"; + value.text = toJSON + (if (isPath ext.crxPath && isString ext.version) then { + external_crx = ext.crxPath; + external_version = ext.version; + } else { + external_update_url = ext.updateUrl; + }); }; - }; in mkIf cfg.enable { home.packages = [ cfg.package ];