nixos/chromium: add the ability to set initial preferences

This commit is contained in:
Yuri Nesterov 2024-03-04 14:39:04 +02:00
parent 2f7fc27d46
commit 960f93fd4f
3 changed files with 41 additions and 0 deletions

View file

@ -98,6 +98,24 @@ in
}
'';
};
initialPrefs = mkOption {
type = types.attrs;
description = lib.mdDoc ''
Initial preferences are used to configure the browser for the first run.
Unlike {option}`programs.chromium.extraOpts`, initialPrefs can be changed by users in the browser settings.
More information can be found in the Chromium documentation:
<https://www.chromium.org/administrators/configuring-other-preferences/>
'';
default = {};
example = literalExpression ''
{
"first_run_tabs" = [
"https://nixos.org/"
];
}
'';
};
};
};
@ -110,6 +128,7 @@ in
{ source = "${cfg.plasmaBrowserIntegrationPackage}/etc/chromium/native-messaging-hosts/org.kde.plasma.browser_integration.json"; };
"chromium/policies/managed/default.json" = lib.mkIf (defaultProfile != {}) { text = builtins.toJSON defaultProfile; };
"chromium/policies/managed/extra.json" = lib.mkIf (cfg.extraOpts != {}) { text = builtins.toJSON cfg.extraOpts; };
"chromium/initial_preferences" = lib.mkIf (cfg.initialPrefs != {}) { text = builtins.toJSON cfg.initialPrefs; };
# for google-chrome https://www.chromium.org/administrators/linux-quick-start
"opt/chrome/native-messaging-hosts/org.kde.plasma.browser_integration.json" = lib.mkIf cfg.enablePlasmaBrowserIntegration
{ source = "${cfg.plasmaBrowserIntegrationPackage}/etc/opt/chrome/native-messaging-hosts/org.kde.plasma.browser_integration.json"; };

View file

@ -216,6 +216,9 @@ let
# (we currently package 1.26 in Nixpkgs while Chromium bundles 1.21):
# Source: https://bugs.chromium.org/p/angleproject/issues/detail?id=7582#c1
./patches/angle-wayland-include-protocol.patch
# Chromium reads initial_preferences from its own executable directory
# This patch modifies it to read /etc/chromium/initial_preferences
./patches/chromium-initial-prefs.patch
] ++ lib.optionals (chromiumVersionAtLeast "120") [
# We need to revert this patch to build M120+ with LLVM 17:
./patches/chromium-120-llvm-17.patch

View file

@ -0,0 +1,19 @@
diff --git a/chrome/browser/first_run/first_run_internal_linux.cc b/chrome/browser/first_run/first_run_internal_linux.cc
index 33fd579012..9a17b54b37 100644
--- a/chrome/browser/first_run/first_run_internal_linux.cc
+++ b/chrome/browser/first_run/first_run_internal_linux.cc
@@ -19,13 +19,7 @@ bool IsOrganicFirstRun() {
}
base::FilePath InitialPrefsPath() {
- // The standard location of the initial prefs is next to the chrome binary.
- base::FilePath dir_exe;
- if (!base::PathService::Get(base::DIR_EXE, &dir_exe)) {
- return base::FilePath();
- }
-
- return installer::InitialPreferences::Path(dir_exe);
+ return base::FilePath("/etc/chromium/initial_preferences");
}
} // namespace internal