Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

nixos/chromium: add the ability to set initial preferences

+41
+19
nixos/modules/programs/chromium.nix
··· 98 98 } 99 99 ''; 100 100 }; 101 + 102 + initialPrefs = mkOption { 103 + type = types.attrs; 104 + description = lib.mdDoc '' 105 + Initial preferences are used to configure the browser for the first run. 106 + Unlike {option}`programs.chromium.extraOpts`, initialPrefs can be changed by users in the browser settings. 107 + More information can be found in the Chromium documentation: 108 + <https://www.chromium.org/administrators/configuring-other-preferences/> 109 + ''; 110 + default = {}; 111 + example = literalExpression '' 112 + { 113 + "first_run_tabs" = [ 114 + "https://nixos.org/" 115 + ]; 116 + } 117 + ''; 118 + }; 101 119 }; 102 120 }; 103 121 ··· 110 128 { source = "${cfg.plasmaBrowserIntegrationPackage}/etc/chromium/native-messaging-hosts/org.kde.plasma.browser_integration.json"; }; 111 129 "chromium/policies/managed/default.json" = lib.mkIf (defaultProfile != {}) { text = builtins.toJSON defaultProfile; }; 112 130 "chromium/policies/managed/extra.json" = lib.mkIf (cfg.extraOpts != {}) { text = builtins.toJSON cfg.extraOpts; }; 131 + "chromium/initial_preferences" = lib.mkIf (cfg.initialPrefs != {}) { text = builtins.toJSON cfg.initialPrefs; }; 113 132 # for google-chrome https://www.chromium.org/administrators/linux-quick-start 114 133 "opt/chrome/native-messaging-hosts/org.kde.plasma.browser_integration.json" = lib.mkIf cfg.enablePlasmaBrowserIntegration 115 134 { source = "${cfg.plasmaBrowserIntegrationPackage}/etc/opt/chrome/native-messaging-hosts/org.kde.plasma.browser_integration.json"; };
+3
pkgs/applications/networking/browsers/chromium/common.nix
··· 216 216 # (we currently package 1.26 in Nixpkgs while Chromium bundles 1.21): 217 217 # Source: https://bugs.chromium.org/p/angleproject/issues/detail?id=7582#c1 218 218 ./patches/angle-wayland-include-protocol.patch 219 + # Chromium reads initial_preferences from its own executable directory 220 + # This patch modifies it to read /etc/chromium/initial_preferences 221 + ./patches/chromium-initial-prefs.patch 219 222 ] ++ lib.optionals (chromiumVersionAtLeast "120") [ 220 223 # We need to revert this patch to build M120+ with LLVM 17: 221 224 ./patches/chromium-120-llvm-17.patch
+19
pkgs/applications/networking/browsers/chromium/patches/chromium-initial-prefs.patch
··· 1 + diff --git a/chrome/browser/first_run/first_run_internal_linux.cc b/chrome/browser/first_run/first_run_internal_linux.cc 2 + index 33fd579012..9a17b54b37 100644 3 + --- a/chrome/browser/first_run/first_run_internal_linux.cc 4 + +++ b/chrome/browser/first_run/first_run_internal_linux.cc 5 + @@ -19,13 +19,7 @@ bool IsOrganicFirstRun() { 6 + } 7 + 8 + base::FilePath InitialPrefsPath() { 9 + - // The standard location of the initial prefs is next to the chrome binary. 10 + - base::FilePath dir_exe; 11 + - if (!base::PathService::Get(base::DIR_EXE, &dir_exe)) { 12 + - return base::FilePath(); 13 + - } 14 + - 15 + - return installer::InitialPreferences::Path(dir_exe); 16 + + return base::FilePath("/etc/chromium/initial_preferences"); 17 + } 18 + 19 + } // namespace internal