Files
home-manager/tests/modules/programs/firefox/config-path-wrapper.nix
Ihar Hrachyshka 922a645e84 firefox: apply configPath to package wrapper
This is a counterpart for: https://github.com/NixOS/nixpkgs/pull/556611

When configPath is overridden, if wrapper supports the new appDataDir
argument, we pass configPath's absolute form to tell the app to look for
its datadir in the correct directory.

This will become necessary on macOS 27+ where Firefox that is not signed
by Mozilla has no access to its default datadir.
2026-09-10 22:57:58 -05:00

91 lines
2.0 KiB
Nix

{
absolute ? false,
configPath,
supportsAppDataDir ? true,
}:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.firefox;
effectiveConfigPath = if absolute then "${config.home.homeDirectory}/${configPath}" else configPath;
expectedAppDataDir = "${config.home.homeDirectory}/${configPath}";
mkPackage =
appDataDir:
config.lib.test.mkStubPackage {
name = "firefox-config-path-test-stub";
buildScript = ''
mkdir -p "$out/lib/mozilla/native-messaging-hosts"
'';
extraAttrs = {
browserName = "firefox";
inherit appDataDir;
meta.mainProgram = "firefox";
};
};
packageWithAppDataDir = lib.makeOverridable (
{
cfg ? { },
extraPolicies ? { },
pkcs11Modules ? [ ],
appDataDir ? null,
}:
builtins.deepSeq [
cfg
extraPolicies
pkcs11Modules
] (mkPackage appDataDir)
) { };
packageWithoutAppDataDir = lib.makeOverridable (
{
cfg ? { },
extraPolicies ? { },
pkcs11Modules ? [ ],
}:
builtins.deepSeq [
cfg
extraPolicies
pkcs11Modules
] (mkPackage null)
) { };
in
{
config = lib.mkIf config.test.enableBig {
home = {
homeDirectory = lib.mkForce (
if pkgs.stdenv.hostPlatform.isDarwin then "/Users/hm-user" else "/home/hm-user"
);
stateVersion = "26.05";
};
programs.firefox = {
enable = true;
configPath = effectiveConfigPath;
package = if supportsAppDataDir then packageWithAppDataDir else packageWithoutAppDataDir;
profiles.test.settings."general.smoothScroll" = false;
};
assertions = [
{
assertion =
cfg.finalPackage.appDataDir == (if supportsAppDataDir then expectedAppDataDir else null);
message = "Firefox wrapper received an unexpected appDataDir";
}
];
mozilla.firefoxNativeMessagingHosts = lib.mkForce [ ];
nmt.script = ''
assertFileExists "home-files/${configPath}/profiles.ini"
'';
};
}