Skip to content

Commit a846d21

Browse files
committed
progs: firefox: *.userChrome may be path or drv
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"; ```
1 parent d094c67 commit a846d21

File tree

1 file changed

+68
-51
lines changed

1 file changed

+68
-51
lines changed

modules/programs/firefox/mkFirefoxModule.nix

+68-51
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,12 @@ in {
358358
userChrome = mkOption {
359359
type = types.oneOf [ types.lines types.path ];
360360
default = "";
361-
description = "Custom ${appName} user chrome CSS.";
361+
description = ''
362+
Custom ${appName} user chrome CSS.
363+
364+
This can be a path to a file or directory in the nix store,
365+
or a derivation, or a verbatim multi-line string.
366+
'';
362367
example = ''
363368
/* Hide tab bar in FF Quantum */
364369
@-moz-document url(chrome://browser/content/browser.xul), url(chrome://browser/content/browser.xhtml) {
@@ -754,66 +759,78 @@ in {
754759
"${cfg.configPath}/profiles.ini" =
755760
mkIf (cfg.profiles != { }) { text = profilesIni; };
756761
}] ++ lib.flip mapAttrsToList cfg.profiles (_: profile:
757-
# Merge the regular profile settings with extension settings
758-
mkMerge ([{
759-
"${profilesPath}/${profile.path}/.keep".text = "";
760-
761-
"${profilesPath}/${profile.path}/chrome/userChrome.css" =
762-
mkIf (profile.userChrome != "") (let
763-
key =
764-
if builtins.isString profile.userChrome then "text" else "source";
765-
in { "${key}" = profile.userChrome; });
766-
767-
"${profilesPath}/${profile.path}/chrome/userContent.css" =
768-
mkIf (profile.userContent != "") (let
769-
key = if builtins.isString profile.userContent then
770-
"text"
771-
else
772-
"source";
773-
in { "${key}" = profile.userContent; });
774-
775-
"${profilesPath}/${profile.path}/user.js" = mkIf (profile.preConfig
776-
!= "" || profile.settings != { } || profile.extraConfig != ""
777-
|| profile.bookmarks.configFile != null) {
778-
text =
779-
mkUserJs profile.preConfig profile.settings profile.extraConfig
780-
profile.bookmarks.configFile profile.extensions.settings;
781-
};
762+
let
763+
chromePath = if lib.pathIsDirectory profile.userChrome then
764+
"chrome"
765+
else
766+
"chrome/userChrome.css";
767+
sourcePath = if lib.types.path.check profile.userChrome then
768+
profile.userChrome
769+
else
770+
null;
771+
# Merge the regular profile settings with extension settings
772+
in mkMerge [
773+
{
774+
"${profilesPath}/${profile.path}/.keep".text = "";
775+
776+
"${profilesPath}/${profile.path}/${chromePath}" =
777+
if sourcePath == null then {
778+
text = profile.userChrome;
779+
} else {
780+
source = sourcePath;
781+
};
782782

783-
"${profilesPath}/${profile.path}/containers.json" =
784-
mkIf (profile.containers != { }) {
785-
text = mkContainersJson profile.containers;
786-
force = profile.containersForce;
787-
};
783+
"${profilesPath}/${profile.path}/chrome/userContent.css" =
784+
mkIf (profile.userContent != "") (let
785+
key = if builtins.isString profile.userContent then
786+
"text"
787+
else
788+
"source";
789+
in { "${key}" = profile.userContent; });
790+
791+
"${profilesPath}/${profile.path}/user.js" = mkIf (profile.preConfig
792+
!= "" || profile.settings != { } || profile.extraConfig != ""
793+
|| profile.bookmarks.configFile != null) {
794+
text =
795+
mkUserJs profile.preConfig profile.settings profile.extraConfig
796+
profile.bookmarks.configFile profile.extensions.settings;
797+
};
788798

789-
"${profilesPath}/${profile.path}/search.json.mozlz4" =
790-
mkIf (profile.search.enable) {
791-
enable = profile.search.enable;
792-
force = profile.search.force;
793-
source = profile.search.file;
794-
};
799+
"${profilesPath}/${profile.path}/containers.json" =
800+
mkIf (profile.containers != { }) {
801+
text = mkContainersJson profile.containers;
802+
force = profile.containersForce;
803+
};
795804

796-
"${profilesPath}/${profile.path}/extensions" =
797-
mkIf (profile.extensions.packages != [ ]) {
798-
source = let
799-
extensionsEnvPkg = pkgs.buildEnv {
800-
name = "hm-firefox-extensions";
801-
paths = profile.extensions.packages;
802-
};
803-
in "${extensionsEnvPkg}/share/mozilla/${extensionPath}";
804-
recursive = true;
805-
force = true;
806-
};
807-
}] ++
805+
"${profilesPath}/${profile.path}/search.json.mozlz4" =
806+
mkIf (profile.search.enable) {
807+
enable = profile.search.enable;
808+
force = profile.search.force;
809+
source = profile.search.file;
810+
};
811+
812+
"${profilesPath}/${profile.path}/extensions" =
813+
mkIf (profile.extensions.packages != [ ]) {
814+
source = let
815+
extensionsEnvPkg = pkgs.buildEnv {
816+
name = "hm-firefox-extensions";
817+
paths = profile.extensions.packages;
818+
};
819+
in "${extensionsEnvPkg}/share/mozilla/${extensionPath}";
820+
recursive = true;
821+
force = true;
822+
};
823+
}
808824
# Add extension settings as separate attributes
809-
optional (profile.extensions.settings != { }) (mkMerge (mapAttrsToList
825+
(mkIf (profile.extensions.settings != { }) (mkMerge (mapAttrsToList
810826
(name: settingConfig: {
811827
"${profilesPath}/${profile.path}/browser-extension-data/${name}/storage.js" =
812828
{
813829
force = settingConfig.force || profile.extensions.force;
814830
text = lib.generators.toJSON { } settingConfig.settings;
815831
};
816-
}) profile.extensions.settings)))));
832+
}) profile.extensions.settings)))
833+
]));
817834
} // setAttrByPath modulePath {
818835
finalPackage = wrapPackage cfg.package;
819836

0 commit comments

Comments
 (0)