Loading pkgs/pkgs-lib/formats.nix +41 −120 Original line number Diff line number Diff line Loading @@ -126,14 +126,23 @@ optionalAttrs allowAliases aliases php = (import ./formats/php/default.nix { inherit lib pkgs; }).format; json = { }: { /* Creates a structured value type suitable for serialization formats. type = Parameters: - typeName: String describing the format (e.g. "JSON", "YAML", "XML") 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 valueType = nullOr (oneOf [ baseType = oneOf [ bool int float Loading @@ -141,13 +150,19 @@ optionalAttrs allowAliases aliases path (attrsOf valueType) (listOf valueType) ]) // { description = "JSON value"; ]; valueType = (if nullable then nullOr baseType else baseType) // { description = "${typeName} value"; }; in valueType; json = { }: { type = mkStructuredType { typeName = "JSON"; }; generate = name: value: pkgs.callPackage ( Loading Loading @@ -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"; }; }; Loading @@ -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"; }; }; Loading Loading @@ -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: Loading Loading @@ -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: Loading Loading @@ -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: { Loading Loading @@ -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: Loading Loading
pkgs/pkgs-lib/formats.nix +41 −120 Original line number Diff line number Diff line Loading @@ -126,14 +126,23 @@ optionalAttrs allowAliases aliases php = (import ./formats/php/default.nix { inherit lib pkgs; }).format; json = { }: { /* Creates a structured value type suitable for serialization formats. type = Parameters: - typeName: String describing the format (e.g. "JSON", "YAML", "XML") 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 valueType = nullOr (oneOf [ baseType = oneOf [ bool int float Loading @@ -141,13 +150,19 @@ optionalAttrs allowAliases aliases path (attrsOf valueType) (listOf valueType) ]) // { description = "JSON value"; ]; valueType = (if nullable then nullOr baseType else baseType) // { description = "${typeName} value"; }; in valueType; json = { }: { type = mkStructuredType { typeName = "JSON"; }; generate = name: value: pkgs.callPackage ( Loading Loading @@ -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"; }; }; Loading @@ -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"; }; }; Loading Loading @@ -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: Loading Loading @@ -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: Loading Loading @@ -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: { Loading Loading @@ -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: Loading