From 93b52ce0bde1d44d2133d89045d1f5ae17f39e45 Mon Sep 17 00:00:00 2001
From: polykernel <81340136+polykernel@users.noreply.github.com>
Date: Fri, 3 Sep 2021 10:54:39 -0400
Subject: [PATCH] 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.
---
modules/programs/chromium.nix | 62 +++++++++++++++++++++++++++--------
1 file changed, 48 insertions(+), 14 deletions(-)
diff --git a/modules/programs/chromium.nix b/modules/programs/chromium.nix
index 5a10fe760..530748ec2 100644
--- a/modules/programs/chromium.nix
+++ b/modules/programs/chromium.nix
@@ -4,6 +4,14 @@ with lib;
let
+ supportedBrowsers = [
+ "chromium"
+ "google-chrome"
+ "google-chrome-beta"
+ "google-chrome-dev"
+ "brave"
+ ];
+
browserModule = defaultPkg: name: visible:
let
browser = (builtins.parseDrvName defaultPkg.name).name;
@@ -11,10 +19,10 @@ let
in {
enable = mkOption {
inherit visible;
+ type = types.bool;
default = false;
example = true;
description = "Whether to enable ${name}.";
- type = lib.types.bool;
};
package = mkOption {
@@ -24,6 +32,25 @@ let
defaultText = literalExpression "pkgs.${browser}";
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}.
+
+ Note this option does not have any effect when using a
+ custom package for .
+
+ For a list of common switches, see
+ Chrome switches.
+
+ To search switches for other components, see
+ Chromium codesearch.
+ '';
+ };
} // optionalAttrs (!isProprietaryChrome) {
# Extensions do not work with Google Chrome
# see https://github.com/nix-community/home-manager/issues/1383
@@ -105,6 +132,7 @@ let
drvName = (builtins.parseDrvName cfg.package.name).name;
browser = if drvName == "ungoogled-chromium" then "chromium" else drvName;
+ isProprietaryChrome = hasPrefix "google-chrome" drvName;
darwinDirs = {
chromium = "Chromium";
@@ -135,9 +163,19 @@ let
in mkIf cfg.enable {
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 {
# Extensions do not work with the proprietary Google Chrome version
# see https://github.com/nix-community/home-manager/issues/1383
@@ -149,20 +187,16 @@ in {
];
options.programs = {
- chromium = browserModule pkgs.chromium "Chromium" true;
- google-chrome = browserModule pkgs.google-chrome "Google Chrome" false;
+ chromium = browserModule browserPkgs.chromium "Chromium" true;
+ google-chrome =
+ browserModule browserPkgs.google-chrome "Google Chrome" false;
google-chrome-beta =
- browserModule pkgs.google-chrome-beta "Google Chrome Beta" false;
+ browserModule browserPkgs.google-chrome-beta "Google Chrome Beta" false;
google-chrome-dev =
- browserModule pkgs.google-chrome-dev "Google Chrome Dev" false;
- brave = browserModule pkgs.brave "Brave Browser" false;
+ browserModule browserPkgs.google-chrome-dev "Google Chrome Dev" false;
+ brave = browserModule browserPkgs.brave "Brave Browser" false;
};
- config = mkMerge [
- (browserConfig config.programs.chromium)
- (browserConfig config.programs.google-chrome)
- (browserConfig config.programs.google-chrome-beta)
- (browserConfig config.programs.google-chrome-dev)
- (browserConfig config.programs.brave)
- ];
+ config = mkMerge
+ (map (browser: browserConfig config.programs.${browser}) supportedBrowsers);
}