1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

chromium: add commandLineArgs option

- Add support for command line arguments, this allows arguments to be
  persistently set if needed (i.e workaround hardware bugs or enabling
  certain flags).
- Document setting a custom package will nullify the `commandLineArgs`
  option.
- Fix `mkRemovedOption` assertion from being apply even when the
  `extensions` option is unused for google chrome modules.
This commit is contained in:
polykernel 2021-09-03 10:54:39 -04:00 committed by Robert Helgesson
parent 990ca662c4
commit 93b52ce0bd
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -4,6 +4,14 @@ with lib;
let let
supportedBrowsers = [
"chromium"
"google-chrome"
"google-chrome-beta"
"google-chrome-dev"
"brave"
];
browserModule = defaultPkg: name: visible: browserModule = defaultPkg: name: visible:
let let
browser = (builtins.parseDrvName defaultPkg.name).name; browser = (builtins.parseDrvName defaultPkg.name).name;
@ -11,10 +19,10 @@ let
in { in {
enable = mkOption { enable = mkOption {
inherit visible; inherit visible;
type = types.bool;
default = false; default = false;
example = true; example = true;
description = "Whether to enable ${name}."; description = "Whether to enable ${name}.";
type = lib.types.bool;
}; };
package = mkOption { package = mkOption {
@ -24,6 +32,25 @@ let
defaultText = literalExpression "pkgs.${browser}"; defaultText = literalExpression "pkgs.${browser}";
description = "The ${name} package to use."; description = "The ${name} package to use.";
}; };
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}.
</para><para>
Note this option does not have any effect when using a
custom package for <option>programs.${browser}.package</option>.
</para><para>
For a list of common switches, see
<link xlink:href="https://chromium.googlesource.com/chromium/src/+/refs/heads/main/chrome/common/chrome_switches.cc">Chrome switches</link>.
</para><para>
To search switches for other components, see
<link xlink:href="https://source.chromium.org/search?q=file:switches.cc&amp;ss=chromium%2Fchromium%2Fsrc">Chromium codesearch</link>.
'';
};
} // optionalAttrs (!isProprietaryChrome) { } // optionalAttrs (!isProprietaryChrome) {
# Extensions do not work with Google Chrome # Extensions do not work with Google Chrome
# see https://github.com/nix-community/home-manager/issues/1383 # see https://github.com/nix-community/home-manager/issues/1383
@ -105,6 +132,7 @@ let
drvName = (builtins.parseDrvName cfg.package.name).name; drvName = (builtins.parseDrvName cfg.package.name).name;
browser = if drvName == "ungoogled-chromium" then "chromium" else drvName; browser = if drvName == "ungoogled-chromium" then "chromium" else drvName;
isProprietaryChrome = hasPrefix "google-chrome" drvName;
darwinDirs = { darwinDirs = {
chromium = "Chromium"; chromium = "Chromium";
@ -135,9 +163,19 @@ let
in mkIf cfg.enable { in mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
home.file = listToAttrs (map extensionJson (cfg.extensions or [ ])); home.file = optionalAttrs (!isProprietaryChrome)
(listToAttrs (map extensionJson cfg.extensions));
}; };
browserPkgs = genAttrs supportedBrowsers (browser:
let cfg = config.programs.${browser};
in if cfg.commandLineArgs != [ ] then
pkgs.${browser}.override {
commandLineArgs = concatStringsSep " " cfg.commandLineArgs;
}
else
pkgs.${browser});
in { in {
# Extensions do not work with the proprietary Google Chrome version # Extensions do not work with the proprietary Google Chrome version
# see https://github.com/nix-community/home-manager/issues/1383 # see https://github.com/nix-community/home-manager/issues/1383
@ -149,20 +187,16 @@ in {
]; ];
options.programs = { options.programs = {
chromium = browserModule pkgs.chromium "Chromium" true; chromium = browserModule browserPkgs.chromium "Chromium" true;
google-chrome = browserModule pkgs.google-chrome "Google Chrome" false; google-chrome =
browserModule browserPkgs.google-chrome "Google Chrome" false;
google-chrome-beta = google-chrome-beta =
browserModule pkgs.google-chrome-beta "Google Chrome Beta" false; browserModule browserPkgs.google-chrome-beta "Google Chrome Beta" false;
google-chrome-dev = google-chrome-dev =
browserModule pkgs.google-chrome-dev "Google Chrome Dev" false; browserModule browserPkgs.google-chrome-dev "Google Chrome Dev" false;
brave = browserModule pkgs.brave "Brave Browser" false; brave = browserModule browserPkgs.brave "Brave Browser" false;
}; };
config = mkMerge [ config = mkMerge
(browserConfig config.programs.chromium) (map (browser: browserConfig config.programs.${browser}) supportedBrowsers);
(browserConfig config.programs.google-chrome)
(browserConfig config.programs.google-chrome-beta)
(browserConfig config.programs.google-chrome-dev)
(browserConfig config.programs.brave)
];
} }