diff --git a/modules/programs/firefox/default.nix b/modules/programs/firefox/default.nix index 0de07b275a..6a2961aaae 100644 --- a/modules/programs/firefox/default.nix +++ b/modules/programs/firefox/default.nix @@ -93,6 +93,17 @@ in config = lib.mkIf cfg.enable { warnings = lib.optional linuxConfigPathStateVersion.shouldWarn linuxConfigPathStateVersion.warning; + # On macOS 27+, Firefox builds not signed by Mozilla cannot access the + # traditional data directory. Use org.nixos.firefox directory instead. + # When package is null, we don't know if it's a signed version (e.g. + # firefox-bin-unwrapped or from Homebrew) or not, so we leave it up to the + # user to adjust as needed. + programs.firefox.configPath = lib.mkIf ( + pkgs.stdenv.hostPlatform.isDarwin + && cfg.package != null + && lib.versionAtLeast config.home.stateVersion "26.11" + ) (lib.mkDefault "Library/Application Support/org.nixos.firefox"); + mozilla.firefoxNativeMessagingHosts = cfg.nativeMessagingHosts # package configured native messaging hosts (entire browser actually) diff --git a/tests/modules/programs/firefox/config-path-darwin-default.nix b/tests/modules/programs/firefox/config-path-darwin-default.nix new file mode 100644 index 0000000000..4321da2187 --- /dev/null +++ b/tests/modules/programs/firefox/config-path-darwin-default.nix @@ -0,0 +1,74 @@ +{ + expectedDarwinPath, + packageIsNull ? false, + stateVersion, +}: +{ + config, + lib, + pkgs, + ... +}: +let + cfg = config.programs.firefox; + + expectedConfigPath = + if pkgs.stdenv.hostPlatform.isDarwin then expectedDarwinPath else ".config/mozilla/firefox"; + + expectedAppDataDir = + if + pkgs.stdenv.hostPlatform.isDarwin && !packageIsNull && lib.versionAtLeast stateVersion "26.11" + then + "${config.home.homeDirectory}/${expectedDarwinPath}" + else + null; + + firefoxPackage = lib.makeOverridable ( + { + cfg ? { }, + extraPolicies ? { }, + pkcs11Modules ? [ ], + appDataDir ? null, + }: + builtins.deepSeq + [ + cfg + extraPolicies + pkcs11Modules + ] + ( + config.lib.test.mkStubPackage { + name = "firefox-config-path-darwin-default-test-stub"; + extraAttrs = { + browserName = "firefox"; + inherit appDataDir; + meta.mainProgram = "firefox"; + }; + } + ) + ) { }; +in +{ + config = lib.mkIf config.test.enableBig { + home.stateVersion = stateVersion; + + programs.firefox = { + enable = true; + package = if packageIsNull then null else firefoxPackage; + profiles.test.settings."general.smoothScroll" = false; + }; + + assertions = [ + { + assertion = cfg.configPath == expectedConfigPath; + message = "Firefox configPath has an unexpected default"; + } + { + assertion = cfg.finalPackage == null || cfg.finalPackage.appDataDir == expectedAppDataDir; + message = "Firefox wrapper received an unexpected appDataDir"; + } + ]; + + mozilla.firefoxNativeMessagingHosts = lib.mkForce [ ]; + }; +} diff --git a/tests/modules/programs/firefox/default.nix b/tests/modules/programs/firefox/default.nix index 86a4469b1a..18570e51b5 100644 --- a/tests/modules/programs/firefox/default.nix +++ b/tests/modules/programs/firefox/default.nix @@ -4,6 +4,19 @@ "firefox-bookmarks-legacy-attrset-warning" = ./bookmarks-legacy-attrset-warning.nix; "firefox-config-path-explicit-legacy" = ./config-path-explicit-legacy.nix; "firefox-config-path-explicit-xdg" = ./config-path-explicit-xdg.nix; + "firefox-config-path-darwin-default-current" = import ./config-path-darwin-default.nix { + expectedDarwinPath = "Library/Application Support/org.nixos.firefox"; + stateVersion = "26.11"; + }; + "firefox-config-path-darwin-default-legacy" = import ./config-path-darwin-default.nix { + expectedDarwinPath = "Library/Application Support/Firefox"; + stateVersion = "26.05"; + }; + "firefox-config-path-darwin-default-null-package" = import ./config-path-darwin-default.nix { + expectedDarwinPath = "Library/Application Support/Firefox"; + packageIsNull = true; + stateVersion = "26.11"; + }; "firefox-config-path-wrapper-absolute" = import ./config-path-wrapper.nix { absolute = true; configPath = "Library/Application Support/org.nixos.firefox";