firefox: fix bookmarks backwards compatibility

The legacy attrset option type for `firefox.profiles.<name>.bookmarks`
was accidentally removed in 9d55428. This adds back support for this
type by refactoring the bookmarks submodule. This also adds a new test
ensuring this won't happen again.
This commit is contained in:
bricked 2025-03-20 18:08:40 +01:00 committed by Austin Horstman
parent 5ff90f09d1
commit 62d6a8931e
7 changed files with 167 additions and 70 deletions

View file

@ -158,6 +158,8 @@ let
})
else
(pkgs.wrapFirefox.override { config = bcfg; }) package { };
bookmarkTypes = import ./profiles/bookmark-types.nix { inherit lib; };
in {
options = setAttrByPath modulePath {
enable = mkOption {
@ -380,7 +382,7 @@ in {
bookmarks = mkOption {
type = (with types;
coercedTo (listOf anything) (bookmarks:
coercedTo bookmarkTypes.settingsType (bookmarks:
warn ''
${cfg.name} bookmarks have been refactored into a submodule that now explicitly require a 'force' option to be enabled.

View file

@ -0,0 +1,70 @@
{ lib, ... }:
with lib;
rec {
settingsType = with types;
coercedTo (addCheck (attrsOf nodeType) (attrs: !(attrs ? settings)))
attrValues (listOf nodeType);
bookmarkSubmodule = types.submodule ({ name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
description = "Bookmark name.";
};
tags = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Bookmark tags.";
};
keyword = mkOption {
type = types.nullOr types.str;
default = null;
description = "Bookmark search keyword.";
};
url = mkOption {
type = types.str;
description = "Bookmark url, use %s for search terms.";
};
};
}) // {
description = "bookmark submodule";
};
bookmarkType = types.addCheck bookmarkSubmodule (x: x ? "url");
directoryType = types.submodule ({ name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
description = "Directory name.";
};
bookmarks = mkOption {
type = types.listOf nodeType;
default = [ ];
description = "Bookmarks within directory.";
};
toolbar = mkOption {
type = types.bool;
default = false;
description = ''
Make this the toolbar directory. Note, this does _not_
mean that this directory will be added to the toolbar,
this directory _is_ the toolbar.
'';
};
};
}) // {
description = "directory submodule";
};
nodeType = types.either bookmarkType directoryType;
}

View file

@ -3,66 +3,9 @@
with lib;
let
bookmarkSubmodule = types.submodule ({ name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
description = "Bookmark name.";
};
bookmarkTypes = import ./bookmark-types.nix { inherit lib; };
tags = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Bookmark tags.";
};
keyword = mkOption {
type = types.nullOr types.str;
default = null;
description = "Bookmark search keyword.";
};
url = mkOption {
type = types.str;
description = "Bookmark url, use %s for search terms.";
};
};
}) // {
description = "bookmark submodule";
};
bookmarkType = types.addCheck bookmarkSubmodule (x: x ? "url");
directoryType = types.submodule ({ name, ... }: {
options = {
name = mkOption {
type = types.str;
default = name;
description = "Directory name.";
};
bookmarks = mkOption {
type = types.listOf nodeType;
default = [ ];
description = "Bookmarks within directory.";
};
toolbar = mkOption {
type = types.bool;
default = false;
description = ''
Make this the toolbar directory. Note, this does _not_
mean that this directory will be added to the toolbar,
this directory _is_ the toolbar.
'';
};
};
}) // {
description = "directory submodule";
};
nodeType = types.either bookmarkType directoryType;
inherit (bookmarkTypes) settingsType;
bookmarksFile = bookmarks:
let
@ -141,8 +84,7 @@ in {
};
settings = mkOption {
type = with types;
coercedTo (attrsOf nodeType) attrValues (listOf nodeType);
type = settingsType;
default = [ ];
example = literalExpression ''
[