Skip to content
Merged
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
161 changes: 41 additions & 120 deletions pkgs/pkgs-lib/formats.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,42 @@ optionalAttrs allowAliases aliases

php = (import ./formats/php/default.nix { inherit lib pkgs; }).format;

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

Parameters:
- typeName: String describing the format (e.g. "JSON", "YAML", "XML")
Comment thread
h7x4 marked this conversation as resolved.

Returns a type suitable for structured data formats that supports:
- Basic types: boolean, integer, float, string, path
- Complex types: attribute sets and lists
*/
mkStructuredType =
{
typeName,
nullable ? true,
}:
let
baseType = oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
];
valueType = (if nullable then nullOr baseType else baseType) // {
description = "${typeName} value";
};
in
valueType;

json =
{ }:
{

type =
let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "JSON value";
};
in
valueType;
type = mkStructuredType { typeName = "JSON"; };

generate =
name: value:
Expand All @@ -160,7 +175,7 @@ optionalAttrs allowAliases aliases
preferLocalBuild = true;
}
''
jq . "$valuePath"> $out
jq . "$valuePath" > $out
''
) { };

Expand All @@ -187,23 +202,7 @@ optionalAttrs allowAliases aliases
''
) { };

type =
let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "YAML 1.1 value";
};
in
valueType;
type = mkStructuredType { typeName = "YAML 1.1"; };

};

Expand All @@ -226,23 +225,7 @@ optionalAttrs allowAliases aliases
''
) { };

type =
let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "YAML 1.2 value";
};
in
valueType;
type = mkStructuredType { typeName = "YAML 1.2"; };

};

Expand Down Expand Up @@ -491,23 +474,7 @@ optionalAttrs allowAliases aliases
{ }:
json { }
// {
type =
let
valueType =
oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
]
// {
description = "TOML value";
};
in
valueType;
type = mkStructuredType { typeName = "TOML"; };

generate =
name: value:
Expand Down Expand Up @@ -540,23 +507,7 @@ optionalAttrs allowAliases aliases
{ }:
json { }
// {
type =
let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "CDN value";
};
in
valueType;
type = mkStructuredType { typeName = "CDN"; };

generate =
name: value:
Expand Down Expand Up @@ -971,23 +922,9 @@ optionalAttrs allowAliases aliases
pythonVars =
{ }:
{
type =
let
valueType =
nullOr (oneOf [
bool
float
int
path
str
(attrsOf valueType)
(listOf valueType)
])
// {
description = "Python value";
};
in
attrsOf valueType;
type = attrsOf (mkStructuredType {
typeName = "Python";
});

lib = {
mkRaw = value: {
Expand Down Expand Up @@ -1067,23 +1004,7 @@ optionalAttrs allowAliases aliases
}:
if format == "badgerfish" then
{
type =
let
valueType =
nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
])
// {
description = "XML value";
};
in
valueType;
type = mkStructuredType { typeName = "XML"; };

generate =
name: value:
Expand Down
Loading