firefox: default configPath to XDG on 26.05

Use `lib.hm.deprecations.mkStateVersionOptionDefault` to keep the legacy `.mozilla/firefox` default for existing configurations while switching new Linux configurations to `"${config.xdg.configHome}/mozilla/firefox"`.

Add focused tests for the legacy and XDG defaults plus a news entry describing the transition.

Closes #8200.
Supersedes #8716 and the earlier attempt in #8672.

Co-authored-by: Heitor <44377258+HeitorAugustoLN@users.noreply.github.com>
This commit is contained in:
Austin Horstman
2026-04-23 19:00:27 -05:00
parent 4bf1f0bcd1
commit b869d6cadb
10 changed files with 143 additions and 4 deletions

View File

@@ -53,3 +53,7 @@ changes are only active if the `home.stateVersion` option is set to
- The options [](#opt-programs.neovim.withPython3) and
[](#opt-programs.neovim.withRuby) now default to `false` following nixpkgs
- On Linux, `programs.firefox.configPath` now defaults to
`"${config.xdg.configHome}/mozilla/firefox"` for `home.stateVersion = "26.05"` and later.
Older state versions keep the legacy default of `".mozilla/firefox"`.

View File

@@ -1,9 +1,44 @@
{ lib, config, ... }:
{
lib,
config,
pkgs,
options,
...
}:
let
inherit (lib) mkRemovedOptionModule;
cfg = config.programs.firefox;
linuxConfigHome = lib.removePrefix "${config.home.homeDirectory}/" config.xdg.configHome;
linuxConfigPathStateVersion = lib.hm.deprecations.mkStateVersionOptionDefault {
inherit (config.home) stateVersion;
since = "26.05";
inherit config;
inherit options;
deferWarningToConfig = true;
optionPath = [
"programs"
"firefox"
"configPath"
];
legacy = {
value = ".mozilla/firefox";
};
current = {
value = "${linuxConfigHome}/mozilla/firefox";
text = ''"''${config.xdg.configHome}/mozilla/firefox"'';
};
shouldWarn =
{ optionUsesDefaultPriority, ... }: optionUsesDefaultPriority && !pkgs.stdenv.hostPlatform.isDarwin;
extraWarning = ''
To migrate to the XDG path, move `~/.mozilla/firefox` to
`$XDG_CONFIG_HOME/mozilla/firefox` and remove the old directory.
Native messaging hosts are not moved by this option change.
'';
};
modulePath = [
"programs"
"firefox"
@@ -28,7 +63,7 @@ in
unwrappedPackageName = "firefox-unwrapped";
platforms.linux = {
configPath = ".mozilla/firefox";
configPath = linuxConfigPathStateVersion.default;
};
platforms.darwin = {
configPath = "Library/Application Support/Firefox";
@@ -56,6 +91,8 @@ in
];
config = lib.mkIf cfg.enable {
warnings = lib.optional linuxConfigPathStateVersion.shouldWarn linuxConfigPathStateVersion.warning;
mozilla.firefoxNativeMessagingHosts =
cfg.nativeMessagingHosts
# package configured native messaging hosts (entire browser actually)

View File

@@ -0,0 +1,48 @@
{
config,
lib,
pkgs,
...
}:
let
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix [
"programs"
"firefox"
];
in
{
imports = [ firefoxMockOverlay ];
config = lib.mkIf (config.test.enableBig && !pkgs.stdenv.hostPlatform.isDarwin) {
home.stateVersion = "25.11";
programs.firefox = {
enable = true;
profiles.test.settings."general.smoothScroll" = false;
};
nmt.script = ''
assertFileRegex \
home-files/.mozilla/firefox/test/user.js \
'user_pref\("general\.smoothScroll", false\);'
assertPathNotExists \
home-files/.config/mozilla/firefox/test/user.js
'';
test.asserts.warnings.expected = [
''
The default value of `programs.firefox.configPath` has changed from `".mozilla/firefox"` to `"/home/hm-user/.config/mozilla/firefox"`.
You are currently using the legacy default (`".mozilla/firefox"`) because `home.stateVersion` is less than "26.05".
To silence this warning and keep legacy behavior, set:
programs.firefox.configPath = ".mozilla/firefox";
To adopt the new default behavior, set:
programs.firefox.configPath = "/home/hm-user/.config/mozilla/firefox";
To migrate to the XDG path, move `~/.mozilla/firefox` to
`$XDG_CONFIG_HOME/mozilla/firefox` and remove the old directory.
Native messaging hosts are not moved by this option change.
''
];
};
}

View File

@@ -0,0 +1,34 @@
{
config,
lib,
pkgs,
...
}:
let
firefoxMockOverlay = import ./setup-firefox-mock-overlay.nix [
"programs"
"firefox"
];
in
{
imports = [ firefoxMockOverlay ];
config = lib.mkIf (config.test.enableBig && !pkgs.stdenv.hostPlatform.isDarwin) {
home.stateVersion = "26.05";
xdg.configHome = "/home/hm-user/.config-custom";
programs.firefox = {
enable = true;
profiles.test.settings."general.smoothScroll" = false;
};
nmt.script = ''
assertFileRegex \
home-files/.config-custom/mozilla/firefox/test/user.js \
'user_pref\("general\.smoothScroll", false\);'
assertPathNotExists \
home-files/.mozilla/firefox/test/user.js
'';
};
}

View File

@@ -1,4 +1,6 @@
{
"firefox-config-path-xdg-default" = ./config-path-xdg-default.nix;
"firefox-config-path-warning" = ./config-path-warning.nix;
"firefox-multiple-derivatives" = ./multiple-derivatives.nix;
}
// (import ./firefox.nix)

View File

@@ -2,6 +2,7 @@ modulePath:
{
config,
lib,
pkgs,
realPkgs,
...
}:
@@ -12,7 +13,14 @@ let
in
lib.mkIf config.test.enableBig (
lib.setAttrByPath modulePath { enable = true; }
lib.setAttrByPath modulePath (
{
enable = true;
}
// lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
configPath = ".mozilla/firefox";
}
)
// {
home.stateVersion = "19.09";

View File

@@ -21,6 +21,7 @@ in
}
// lib.setAttrByPath modulePath {
enable = true;
configPath = lib.mkIf pkgs.stdenv.hostPlatform.isLinux ".mozilla/firefox";
policies = {
BlockAboutConfig = true;
};

View File

@@ -24,6 +24,7 @@ in
}
// lib.setAttrByPath modulePath {
enable = true;
configPath = lib.mkIf pkgs.stdenv.hostPlatform.isLinux ".mozilla/firefox";
profiles.bookmarks = {
settings = {
"general.smoothScroll" = false;

View File

@@ -17,7 +17,10 @@ in
{
home.stateVersion = "19.09";
}
// lib.setAttrByPath modulePath { enable = true; }
// lib.setAttrByPath modulePath {
enable = true;
configPath = ".mozilla/firefox";
}
// {
nmt.script = ''
assertFileRegex \

View File

@@ -8,6 +8,7 @@
lib.recursiveUpdate (import ./thunderbird.nix { inherit config lib pkgs; }) {
programs.firefox = {
enable = true;
configPath = lib.mkIf pkgs.stdenv.hostPlatform.isLinux ".mozilla/firefox";
package = null;
};
}