Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,41 @@ in
Like `wlib.types.attrsRecursive`, but uses `lib.types.lazyAttrsOf` instead.
*/
lazyAttrsRecursive = attrsRecursive true;

/**
Creates a value type suitable for serialization formats.

Parameters:
- typeName: String describing the format (e.g. "JSON", "YAML", "XML")
- nullable: Whether the structured value type allows `null` values.
- extraValueTypes: List of extra value types to allow, e.g. "[ lib.types.luaInline ]"

Returns a type suitable for structured data formats that supports:
- Basic types: boolean, integer, float, string, path
- Complex types: attribute sets and lists
- Other user provided value types
*/
structuredValueWith =
{
typeName,
nullable ? true,
extraValueTypes ? [ ],
}:
let
baseType = lib.types.oneOf (
(lib.toList extraValueTypes)
++ [
lib.types.bool
lib.types.int
lib.types.float
wlib.types.stringable
(lib.types.attrsOf valueType)
(lib.types.listOf valueType)
]
);
valueType = (if nullable then lib.types.nullOr baseType else baseType) // {
description = "${typeName} value";
};
in
valueType;
}
8 changes: 4 additions & 4 deletions wrapperModules/a/alacritty/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
pkgs,
...
}:
let
tomlFmt = pkgs.formats.toml { };
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
default = { };
description = ''
Configuration of alacritty.
Expand Down
9 changes: 6 additions & 3 deletions wrapperModules/a/atuin/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
...
}:
let
tomlFmt = pkgs.formats.toml { };
tomlFmtType = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
in
{
imports = [ wlib.modules.default ];

options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = tomlFmtType;
default = { };
description = ''
Atuin configuration options.
'';
};
server-settings = lib.mkOption {
type = tomlFmt.type;
type = tomlFmtType;
default = { };
description = ''
Atuin server configuration options.
Expand Down
8 changes: 4 additions & 4 deletions wrapperModules/b/bottom/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
pkgs,
...
}:
let
tomlFmt = pkgs.formats.toml { };
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
default = { };
description = ''
Configuration passed to `btm` using `--config_location` flag.
Expand Down
8 changes: 4 additions & 4 deletions wrapperModules/c/claude-code/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
...
}:
let
jsonFmt = pkgs.formats.json { };
jsonFmtType = wlib.types.structuredValueWith { typeName = "JSON"; };
in
{
imports = [ wlib.modules.default ];

options = {

agents = lib.mkOption {
type = jsonFmt.type;
type = jsonFmtType;
default = { };
description = ''
Custom agents to add to Claude Code.
Expand All @@ -37,7 +37,7 @@ in
};

mcpConfig = lib.mkOption {
type = jsonFmt.type;
type = jsonFmtType;
default = { };
description = ''
MCP Server configuration
Expand Down Expand Up @@ -71,7 +71,7 @@ in
};

settings = lib.mkOption {
type = jsonFmt.type;
type = jsonFmtType;
default = { };
description = ''
Claude Code settings
Expand Down
2 changes: 1 addition & 1 deletion wrapperModules/f/fastfetch/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = lib.types.json or (pkgs.formats.json { }).type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
description = ''
Configuration passed to fastfetch using `--config` flag
Expand Down
2 changes: 1 addition & 1 deletion wrapperModules/g/glance/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
inherit (pkgs.formats.yaml { }) type;
type = wlib.types.structuredValueWith { typeName = "YAML 1.1"; };
default = { };
description = ''
Configuration for glance.
Expand Down
9 changes: 6 additions & 3 deletions wrapperModules/h/halloy/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
...
}:
let
tomlFmt = pkgs.formats.toml { };
tomlFmtType = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
inherit (tomlFmt) type;
type = tomlFmtType;
default = { };
description = ''
Configuration settings for halloy. All available options can be
Expand All @@ -31,7 +34,7 @@ in
themes = lib.mkOption {
type = lib.types.attrsOf (
lib.types.oneOf [
tomlFmt.type
tomlFmtType
lib.types.lines
lib.types.path
]
Expand Down
11 changes: 7 additions & 4 deletions wrapperModules/h/helix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
...
}:
let
tomlFmt = pkgs.formats.toml { };
tomlFmtType = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
hasConfig =
config.settings != { }
|| config.extraSettings != ""
Expand All @@ -18,7 +21,7 @@ in
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = tomlFmtType;
description = ''
General settings
See <https://docs.helix-editor.com/configuration.html>
Expand All @@ -33,7 +36,7 @@ in
'';
};
languages = lib.mkOption {
type = tomlFmt.type;
type = tomlFmtType;
description = ''
Language specific settings
See <https://docs.helix-editor.com/languages.html>
Expand All @@ -43,7 +46,7 @@ in
themes = lib.mkOption {
type = lib.types.attrsOf (
lib.types.oneOf [
tomlFmt.type
tomlFmtType
lib.types.lines
]
);
Expand Down
8 changes: 4 additions & 4 deletions wrapperModules/h/himalaya/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
lib,
...
}:
let
tomlFmt = pkgs.formats.toml { };
in
{
imports = [ wlib.modules.default ];

options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
default = { };
description = ''
Configuration for himalaya mail client CLI
Expand Down
5 changes: 1 addition & 4 deletions wrapperModules/h/hyfetch/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
pkgs,
...
}:
let
jsonFormat = pkgs.formats.json { };
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = jsonFormat.type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
description = "JSON config for HyFetch";
example = lib.literalExpression ''
Expand Down
8 changes: 4 additions & 4 deletions wrapperModules/j/jujutsu/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
pkgs,
...
}:
let
tomlFmt = pkgs.formats.toml { };
in
{
imports = [ wlib.modules.default ];
options = {
settings = lib.mkOption {
type = tomlFmt.type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
default = { };
description = ''
Configuration for jujutsu.
Expand Down
4 changes: 1 addition & 3 deletions wrapperModules/m/mdbook/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ let
linkCmds = builtins.concatStringsSep "\n" (map mkLink sortedBook);
};

tomltype = (lib.types.json or (pkgs.formats.json { }).type) // {
description = "nullable TOML value";
};
tomltype = wlib.types.structuredValueWith { typeName = "nullable TOML"; };

book-out-dir = "${top.config.binName}-book-dir";
in
Expand Down
21 changes: 4 additions & 17 deletions wrapperModules/n/neovim/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,10 @@
let
makeWrapper = import wlib.modules.makeWrapper;
inherit (lib) types;
luaType =
types.nullOr (
types.oneOf [
types.bool
types.float
types.int
types.path
types.str
types.luaInline
(types.attrsOf luaType)
(types.listOf luaType)
]
)
// {
description = "lua value";
descriptionClass = "noun";
};
luaType = wlib.types.structuredValueWith {
typeName = "lua";
extraValueTypes = lib.types.luaInline;
};
hostPropagatedOptions =
name: hostConfig:
lib.types.submoduleWith {
Expand Down
15 changes: 9 additions & 6 deletions wrapperModules/n/noctalia-shell/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ in
'';
};
settings = lib.mkOption {
type = lib.types.json or (pkgs.formats.json { }).type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
example = lib.literalExpression ''
{
Expand All @@ -127,7 +127,7 @@ in
};

colors = lib.mkOption {
type = lib.types.json or (pkgs.formats.json { }).type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
example = lib.literalExpression ''
{
Expand Down Expand Up @@ -155,7 +155,10 @@ in

user-templates = lib.mkOption {
default = { };
type = (pkgs.formats.toml { }).type;
type = wlib.types.structuredValueWith {
nullable = false;
typeName = "TOML";
};
example = lib.literalExpression ''
{
templates = {
Expand All @@ -175,7 +178,7 @@ in
};

plugins = lib.mkOption {
type = lib.types.json or (pkgs.formats.json { }).type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
example = lib.literalExpression ''
{
Expand All @@ -202,7 +205,7 @@ in
};

pluginSettings = lib.mkOption {
type = lib.types.attrsOf (lib.types.json or (pkgs.formats.json { }).type);
type = lib.types.attrsOf (wlib.types.structuredValueWith { typeName = "JSON"; });
default = { };
example = lib.literalExpression ''
{
Expand Down Expand Up @@ -275,7 +278,7 @@ in
'';
};
settings = lib.mkOption {
type = lib.types.json or (pkgs.formats.json { }).type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
description = ''
Settings to add to `$NOCTALIA_CONFIG_DIR/plugins/plugin-name/settings.json`
Expand Down
2 changes: 1 addition & 1 deletion wrapperModules/o/opencode/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
imports = [ wlib.modules.default ];
options.settings = lib.mkOption {
type = (pkgs.formats.json { }).type;
type = wlib.types.structuredValueWith { typeName = "JSON"; };
default = { };
description = "Sets OPENCODE_CONFIG for github:sst/opencode";
};
Expand Down
Loading