From 7ede02c32a729db0d6340bdb41d10e73ec511ca0 Mon Sep 17 00:00:00 2001 From: Jacob Birkett Date: Wed, 16 Apr 2025 09:28:18 -0700 Subject: [PATCH] progs: firefox: *.userChrome may be path or drv (#6761) This allows `programs.firefox.profiles.*.userChrome` to be set to a: derivation, path/path-like string to directory or file, or multiline text to be used as content verbatim. This allows setting, for example(s): ```nix programs.firefox.profiles."jacob.default".userChrome = pkgs.wavefox; programs.firefox.profiles."jacob.default".userChrome = "${pkgs.wavefox}/userChrome.css"; ``` --- modules/programs/firefox/mkFirefoxModule.nix | 43 +++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/modules/programs/firefox/mkFirefoxModule.nix b/modules/programs/firefox/mkFirefoxModule.nix index 782ced93..ec7a77cd 100644 --- a/modules/programs/firefox/mkFirefoxModule.nix +++ b/modules/programs/firefox/mkFirefoxModule.nix @@ -397,12 +397,19 @@ in }; userChrome = mkOption { - type = types.oneOf [ - types.lines - types.path - ]; - default = ""; - description = "Custom ${appName} user chrome CSS."; + type = types.nullOr ( + types.oneOf [ + types.lines + types.path + ] + ); + default = null; + description = '' + Custom ${appName} user chrome CSS. + + This can be a path to a file or directory in the Nix store, + or a derivation, or a verbatim multi-line string. + ''; example = '' /* Hide tab bar in FF Quantum */ @-moz-document url(chrome://browser/content/browser.xul), url(chrome://browser/content/browser.xhtml) { @@ -861,21 +868,27 @@ in ] ++ lib.flip mapAttrsToList cfg.profiles ( _: profile: + let + chromePath = if lib.pathIsDirectory profile.userChrome then "chrome" else "chrome/userChrome.css"; + sourcePath = if lib.types.path.check profile.userChrome then profile.userChrome else null; + in # Merge the regular profile settings with extension settings mkMerge ( [ + (mkIf (profile.userChrome != null) { + "${profilesPath}/${profile.path}/${chromePath}" = + if sourcePath == null then + { + text = profile.userChrome; + } + else + { + source = sourcePath; + }; + }) { "${profilesPath}/${profile.path}/.keep".text = ""; - "${profilesPath}/${profile.path}/chrome/userChrome.css" = mkIf (profile.userChrome != "") ( - let - key = if builtins.isString profile.userChrome then "text" else "source"; - in - { - "${key}" = profile.userChrome; - } - ); - "${profilesPath}/${profile.path}/chrome/userContent.css" = mkIf (profile.userContent != "") ( let key = if builtins.isString profile.userContent then "text" else "source";