diff --git a/modules/programs/firefox/mkFirefoxModule.nix b/modules/programs/firefox/mkFirefoxModule.nix index 307d39305..046d55d06 100644 --- a/modules/programs/firefox/mkFirefoxModule.nix +++ b/modules/programs/firefox/mkFirefoxModule.nix @@ -483,25 +483,11 @@ in ( bookmarks: if bookmarks != { } then - lib.warn - '' - ${cfg.name} bookmarks have been refactored into a submodule that now explicitly require a 'force' option to be enabled. - - Replace: - - ${moduleName}.profiles.${name}.bookmarks = [ ... ]; - - With: - - ${moduleName}.profiles.${name}.bookmarks = { - force = true; - settings = [ ... ]; - }; - '' - { - force = true; - settings = bookmarks; - } + { + force = true; + _legacySettings = if builtins.isList bookmarks then "a list" else "an attribute set"; + settings = bookmarks; + } else { } ) @@ -1028,7 +1014,59 @@ in ++ optional (cfg.vendorPath != null) '' Using '${moduleName}.vendorPath' has been deprecated and will be removed in the future. Native messaging hosts will function normally without specifying this path. - ''; + '' + ++ lib.flatten ( + lib.mapAttrsToList ( + name: profile: + lib.optional (profile.bookmarks._legacySettings != null) ( + let + legacySettingsExample = + if profile.bookmarks._legacySettings == "a list" then "[ ... ]" else "{ ... }"; + in + lib.hm.deprecations.mkDeprecatedOptionValueWarning { + option = modulePath ++ [ + "profiles" + name + "bookmarks" + ]; + old = profile.bookmarks._legacySettings; + replacement = "`${ + lib.showOption ( + modulePath + ++ [ + "profiles" + name + "bookmarks" + "settings" + ] + ) + }` with `${ + lib.showOption ( + modulePath + ++ [ + "profiles" + name + "bookmarks" + "force" + ] + ) + } = true`"; + details = '' + Set `force = true` to acknowledge replacing existing custom bookmarks. + + Replace: + ${moduleName}.profiles.${name}.bookmarks = ${legacySettingsExample}; + + With: + ${moduleName}.profiles.${name}.bookmarks = { + force = true; + settings = ${legacySettingsExample}; + }; + ''; + } + ) + ) cfg.profiles + ); targets.darwin.defaults = ( mkIf (cfg.darwinDefaultsId != null && isDarwin) { diff --git a/modules/programs/firefox/profiles/bookmarks.nix b/modules/programs/firefox/profiles/bookmarks.nix index 25fd23483..78a4b468e 100644 --- a/modules/programs/firefox/profiles/bookmarks.nix +++ b/modules/programs/firefox/profiles/bookmarks.nix @@ -84,6 +84,12 @@ in ]; options = { + _legacySettings = mkOption { + type = types.nullOr types.str; + default = null; + visible = false; + }; + enable = mkOption { type = with types; bool; default = config.settings != [ ]; diff --git a/tests/modules/programs/firefox/bookmarks-legacy-attrset-warning.nix b/tests/modules/programs/firefox/bookmarks-legacy-attrset-warning.nix new file mode 100644 index 000000000..187409dae --- /dev/null +++ b/tests/modules/programs/firefox/bookmarks-legacy-attrset-warning.nix @@ -0,0 +1,50 @@ +{ + config, + ... +}: + +let + cfg = config.programs.firefox; +in +{ + imports = [ + (import ./setup-firefox-mock-overlay.nix [ + "programs" + "firefox" + ]) + ]; + + home.stateVersion = "26.05"; + + programs.firefox = { + enable = true; + profiles.default.bookmarks = { + "Home Manager" = { + url = "https://wiki.nixos.org/wiki/Home_Manager"; + }; + }; + }; + + test.asserts.warnings.expected = [ + '' + Using `programs.firefox.profiles.default.bookmarks` as an attribute set is deprecated and will be + removed in a future release. Please use `programs.firefox.profiles.default.bookmarks.settings` with `programs.firefox.profiles.default.bookmarks.force = true` instead. + + Set `force = true` to acknowledge replacing existing custom bookmarks. + + Replace: + programs.firefox.profiles.default.bookmarks = { ... }; + + With: + programs.firefox.profiles.default.bookmarks = { + force = true; + settings = { ... }; + }; + + '' + ]; + + nmt.script = '' + assertFileExists "home-files/${cfg.profilesPath}/default/user.js" + ''; +} diff --git a/tests/modules/programs/firefox/bookmarks-legacy-warning.nix b/tests/modules/programs/firefox/bookmarks-legacy-warning.nix new file mode 100644 index 000000000..5c18ab437 --- /dev/null +++ b/tests/modules/programs/firefox/bookmarks-legacy-warning.nix @@ -0,0 +1,51 @@ +{ + config, + ... +}: + +let + cfg = config.programs.firefox; +in +{ + imports = [ + (import ./setup-firefox-mock-overlay.nix [ + "programs" + "firefox" + ]) + ]; + + home.stateVersion = "26.05"; + + programs.firefox = { + enable = true; + profiles.default.bookmarks = [ + { + name = "Home Manager"; + url = "https://wiki.nixos.org/wiki/Home_Manager"; + } + ]; + }; + + test.asserts.warnings.expected = [ + '' + Using `programs.firefox.profiles.default.bookmarks` as a list is deprecated and will be + removed in a future release. Please use `programs.firefox.profiles.default.bookmarks.settings` with `programs.firefox.profiles.default.bookmarks.force = true` instead. + + Set `force = true` to acknowledge replacing existing custom bookmarks. + + Replace: + programs.firefox.profiles.default.bookmarks = [ ... ]; + + With: + programs.firefox.profiles.default.bookmarks = { + force = true; + settings = [ ... ]; + }; + + '' + ]; + + nmt.script = '' + assertFileExists "home-files/${cfg.profilesPath}/default/user.js" + ''; +} diff --git a/tests/modules/programs/firefox/default.nix b/tests/modules/programs/firefox/default.nix index f3379b44f..082a2231e 100644 --- a/tests/modules/programs/firefox/default.nix +++ b/tests/modules/programs/firefox/default.nix @@ -1,5 +1,7 @@ { lib, ... }: { + "firefox-bookmarks-legacy-warning" = ./bookmarks-legacy-warning.nix; + "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-xdg-default" = ./config-path-xdg-default.nix; diff --git a/tests/modules/programs/firefox/profiles/bookmarks/attrset.nix b/tests/modules/programs/firefox/profiles/bookmarks/attrset.nix index bd157a0a6..9d45517be 100644 --- a/tests/modules/programs/firefox/profiles/bookmarks/attrset.nix +++ b/tests/modules/programs/firefox/profiles/bookmarks/attrset.nix @@ -72,6 +72,25 @@ in }; } // { + test.asserts.warnings.expected = [ + '' + Using `${lib.showOption modulePath}.profiles.bookmarks.bookmarks` as an attribute set is deprecated and will be + removed in a future release. Please use `${lib.showOption modulePath}.profiles.bookmarks.bookmarks.settings` with `${lib.showOption modulePath}.profiles.bookmarks.bookmarks.force = true` instead. + + Set `force = true` to acknowledge replacing existing custom bookmarks. + + Replace: + ${lib.showOption modulePath}.profiles.bookmarks.bookmarks = { ... }; + + With: + ${lib.showOption modulePath}.profiles.bookmarks.bookmarks = { + force = true; + settings = { ... }; + }; + + '' + ]; + nmt.script = '' bookmarksUserJs=$(normalizeStorePaths \ "home-files/${cfg.profilesPath}/bookmarks/user.js")