From 008a16529f3801f502476bdeb2158d510c930200 Mon Sep 17 00:00:00 2001 From: MrQubo Date: Tue, 19 Nov 2024 02:25:59 +0100 Subject: [PATCH] firefox: Enable userChrome in about:config Enable "toolkit.legacyUserProfileCustomizations.stylesheets" in about:config if userChrome or userContent is not empty. --- modules/programs/firefox/mkFirefoxModule.nix | 26 +++++++++++++++- .../programs/firefox/profile-settings.nix | 30 +++++++++++++++---- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/modules/programs/firefox/mkFirefoxModule.nix b/modules/programs/firefox/mkFirefoxModule.nix index 1bb2253f1..cdbb96f7e 100644 --- a/modules/programs/firefox/mkFirefoxModule.nix +++ b/modules/programs/firefox/mkFirefoxModule.nix @@ -682,6 +682,12 @@ in { }; }; + + config = let profile = config; + in { + settings."toolkit.legacyUserProfileCustomizations.stylesheets" = + mkIf (profile.userChrome != "" || profile.userContent != "") true; + }; })); default = { }; description = "Attribute set of ${name} profiles."; @@ -739,7 +745,25 @@ in { (mkNoDuplicateAssertion cfg.profiles "profile") ] ++ (mapAttrsToList (_: profile: mkNoDuplicateAssertion profile.containers "container") - cfg.profiles); + cfg.profiles) ++ ( + # Assert "toolkit.legacyUserProfileCustomizations.stylesheets" is enabled if + # userChrome/userContent is used. + let + + assertProfile = userChromeAttr: profile: + profile.${userChromeAttr} != "" + -> (profile.settings."toolkit.legacyUserProfileCustomizations.stylesheets" + != false); + + mkAssertion = userChromeAttr: { + assertion = + all (assertProfile userChromeAttr) (attrValues cfg.profiles); + message = '' + `${userChromeAttr}` won't work with `settings."toolkit.legacyUserProfileCustomizations.stylesheets"` set to false. + ''; + }; + + in [ (mkAssertion "userChrome") (mkAssertion "userContent") ]); warnings = optional (cfg.enableGnomeExtensions or false) '' Using '${moduleName}.enableGnomeExtensions' has been deprecated and diff --git a/tests/modules/programs/firefox/profile-settings.nix b/tests/modules/programs/firefox/profile-settings.nix index 897067625..482ae95ed 100644 --- a/tests/modules/programs/firefox/profile-settings.nix +++ b/tests/modules/programs/firefox/profile-settings.nix @@ -15,6 +15,9 @@ let name = cfg.wrappedPackageName; }; + userChromeExample = "#example-user-chrome { display: none; }"; + userContentExample = "#example-user-content { display: none; }"; + in { imports = [ firefoxMockOverlay ]; @@ -160,12 +163,17 @@ in { id = 5; containers = { "shopping" = { - id = 6; icon = "circle"; color = "yellow"; }; }; }; + + profiles.userChrome = { + id = 6; + userChrome = userChromeExample; + userContent = userContentExample; + }; } // { nmt.script = let @@ -199,10 +207,6 @@ in { home-files/${cfg.configPath}/test/user.js \ ${withName ./profile-settings-expected-user.js} - assertFileContent \ - home-files/${cfg.configPath}/containers/containers.json \ - ${withName ./profile-settings-expected-containers.json} - bookmarksUserJs=$(normalizeStorePaths \ home-files/${cfg.configPath}/bookmarks/user.js) @@ -236,6 +240,22 @@ in { assertFirefoxSearchContent \ home-files/${cfg.configPath}/searchWithoutDefault/search.json.mozlz4 \ ${withName ./profile-settings-expected-search-without-default.json} + + assertFileContent \ + home-files/${cfg.configPath}/containers/containers.json \ + ${withName ./profile-settings-expected-containers.json} + + assertFileContains \ + home-files/${cfg.configPath}/userChrome/user.js \ + 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true)' + + assertFileContains \ + home-files/${cfg.configPath}/userChrome/chrome/userChrome.css \ + '${userChromeExample}' + + assertFileContains \ + home-files/${cfg.configPath}/userChrome/chrome/userContent.css \ + '${userContentExample}' ''; }); }