mirror of
https://github.com/nix-community/home-manager.git
synced 2026-06-05 21:02:51 +00:00
mkFirefoxModule: allow per-extension settings force
Fixes the force acknowledgement logic for extension settings so an extension-specific force flag is sufficient for that extension. References https://github.com/nix-community/home-manager/discussions/7910
This commit is contained in:
@@ -84,6 +84,10 @@ let
|
||||
extensionSettingsNeedForce =
|
||||
extensionSettings: builtins.any (ext: ext.settings != { }) (attrValues extensionSettings);
|
||||
|
||||
extensionSettingsMissingForce =
|
||||
extensionSettings:
|
||||
builtins.any (ext: ext.settings != { } && !ext.force) (attrValues extensionSettings);
|
||||
|
||||
mkUserJs =
|
||||
prePrefs: prefs: extraPrefs: bookmarksFile: extensions:
|
||||
let
|
||||
@@ -836,11 +840,13 @@ in
|
||||
assertions = [
|
||||
(mkNoDuplicateAssertion config.containers "container")
|
||||
{
|
||||
assertion = !(extensionSettingsNeedForce config.extensions.settings) || config.extensions.force;
|
||||
assertion = !(extensionSettingsMissingForce config.extensions.settings) || config.extensions.force;
|
||||
message = ''
|
||||
Using '${lib.showOption profilePath}.extensions.settings' will override all
|
||||
previous extensions settings. Enable
|
||||
'${lib.showOption profilePath}.extensions.force' to acknowledge this.
|
||||
previous extensions settings. Enable either
|
||||
'${lib.showOption profilePath}.extensions.force' or the corresponding
|
||||
'${lib.showOption profilePath}.extensions.settings.<extensionId>.force'
|
||||
to acknowledge this.
|
||||
'';
|
||||
}
|
||||
]
|
||||
|
||||
@@ -33,6 +33,9 @@ builtins.mapAttrs
|
||||
"${name}-profiles-extensions" = ./profiles/extensions;
|
||||
"${name}-profiles-extensions-assertions" = ./profiles/extensions/assertions.nix;
|
||||
"${name}-profiles-extensions-extensible" = ./profiles/extensions/extensible.nix;
|
||||
"${name}-profiles-extensions-per-extension-force" = ./profiles/extensions/per-extension-force.nix;
|
||||
"${name}-profiles-extensions-per-extension-force-assertions" =
|
||||
./profiles/extensions/per-extension-force-assertions.nix;
|
||||
"${name}-profiles-extensions-exhaustive" = ./profiles/extensions/exhaustive.nix;
|
||||
"${name}-profiles-extensions-exact" = ./profiles/extensions/exact.nix;
|
||||
"${name}-profiles-handlers" = ./profiles/handlers;
|
||||
|
||||
@@ -55,8 +55,10 @@ in
|
||||
test.asserts.assertions.expected = [
|
||||
''
|
||||
Using '${lib.showOption modulePath}.profiles.extensions.extensions.settings' will override all
|
||||
previous extensions settings. Enable
|
||||
'${lib.showOption modulePath}.profiles.extensions.extensions.force' to acknowledge this.
|
||||
previous extensions settings. Enable either
|
||||
'${lib.showOption modulePath}.profiles.extensions.extensions.force' or the corresponding
|
||||
'${lib.showOption modulePath}.profiles.extensions.extensions.settings.<extensionId>.force'
|
||||
to acknowledge this.
|
||||
''
|
||||
''
|
||||
Extension uBlock0@raymondhill.net requests permissions that weren't
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
modulePath:
|
||||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
firefoxMockOverlay = import ../../setup-firefox-mock-overlay.nix modulePath;
|
||||
in
|
||||
{
|
||||
imports = [ firefoxMockOverlay ];
|
||||
|
||||
config = lib.mkIf config.test.enableBig (
|
||||
lib.setAttrByPath modulePath {
|
||||
enable = true;
|
||||
profiles.extensions = {
|
||||
extensions.settings = {
|
||||
"forced@example.com" = {
|
||||
force = true;
|
||||
settings.enabled = true;
|
||||
};
|
||||
"unforced@example.com".settings.enabled = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
// {
|
||||
test.asserts.assertions.expected = [
|
||||
''
|
||||
Using '${lib.showOption modulePath}.profiles.extensions.extensions.settings' will override all
|
||||
previous extensions settings. Enable either
|
||||
'${lib.showOption modulePath}.profiles.extensions.extensions.force' or the corresponding
|
||||
'${lib.showOption modulePath}.profiles.extensions.extensions.settings.<extensionId>.force'
|
||||
to acknowledge this.
|
||||
''
|
||||
];
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
modulePath:
|
||||
{ config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = lib.getAttrFromPath modulePath config;
|
||||
|
||||
firefoxMockOverlay = import ../../setup-firefox-mock-overlay.nix modulePath;
|
||||
in
|
||||
{
|
||||
imports = [ firefoxMockOverlay ];
|
||||
|
||||
config = lib.mkIf config.test.enableBig (
|
||||
lib.setAttrByPath modulePath {
|
||||
enable = true;
|
||||
profiles.extensions = {
|
||||
extensions.settings."uBlock0@raymondhill.net" = {
|
||||
force = true;
|
||||
settings = {
|
||||
selectedFilterLists = [
|
||||
"ublock-filters"
|
||||
"ublock-badware"
|
||||
"ublock-privacy"
|
||||
"ublock-unbreak"
|
||||
"ublock-quick-fixes"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
// {
|
||||
nmt.script = ''
|
||||
assertFileContent \
|
||||
"home-files/${cfg.profilesPath}/extensions/browser-extension-data/uBlock0@raymondhill.net/storage.js" \
|
||||
${./expected-storage.js}
|
||||
|
||||
assertFileContent \
|
||||
"home-files/${cfg.profilesPath}/extensions/user.js" \
|
||||
${./expected-user.js}
|
||||
'';
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user