Commit Graph

92 Commits

Author SHA1 Message Date
Peder Bergebakken Sundt
e1b62608ae formats: use AST-based approach for codegen (#549114) 2026-08-12 19:02:33 +00:00
h7x4
18bcb2238b formats: use AST-based approach for codegen 2026-08-04 20:24:50 +09:00
Robert Schütz
34ab5d3a78 formats.yaml_1_1: use remarshal v2 2026-07-30 09:55:06 -07:00
nixpkgs-ci[bot]
b3d68622a1 Merge master into staging-nixos 2026-06-24 00:41:40 +00:00
Yuriy Taraday
efdeeebcb9 Reapply "pkgs-lib/formats: Use .attrs.json where possible"
This expands on https://github.com/NixOS/nixpkgs/pull/498928 that
introduced __structuredAttrs here by actually using data in
`.attrs.json` when it makes sense, instead of relying on environment
variables.

This reverts commit bf6ada5d78.
This reapplies commit 691dc02df0.
2026-06-23 22:01:42 +02:00
Yuriy Taraday
7601f8a108 pkgs-lib/formats: Add tests for serializing null values
In the effort to pass values directly as structured values, we ran into
issue with serializing null's.
This adds tests for null for all formats that support it and negative
tests for some others.

See https://github.com/NixOS/nixpkgs/pull/524404#issuecomment-4665694636
2026-06-23 19:00:26 +02:00
Yuriy Taraday
f995f8cca8 Reapply "pkgs-lib/formats: Use .attrs.json directly for TOML"
This reverts commit 36709df191.
2026-06-23 18:26:12 +02:00
Yt
25e5e0a252 pkgs.formats.elixirConf: Allow for Elixir charlists (#532327) 2026-06-19 01:41:25 +00:00
Pol Dellaiera
29c66c6eaa pkgs.formats.configobj: init
Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
2026-06-16 20:58:27 +02:00
Kerstin Humm
4e14aa4aa4 pkgs.formats.elixirConf: Allow for Elixir charlists
These are needed for defining strings that reach through to Erlang code
2026-06-16 15:38:43 +02:00
isabel
a428fc7bf4 pkgs.formats: performance cleanups (#529122) 2026-06-10 20:26:41 +00:00
Matt Sturgeon
36709df191 Revert "pkgs-lib/formats: Use .attrs.json directly for TOML" 2026-06-10 13:30:28 +01:00
K900
bf6ada5d78 Revert "pkgs-lib/formats: Use .attrs.json where possible" 2026-06-10 09:28:51 +03:00
Eman Resu
623c813d5f pkgs.formats: move toJSON to global scope 2026-06-07 08:49:02 -04:00
Eman Resu
f214820f08 pkgs.formats.nixConf: use package from lib.types explicitly
This was actually being set to the package attribute for the function,
which is definitely not what we want.
2026-06-07 08:48:20 -04:00
Eman Resu
d6c42b7725 pkgs.formats: use lib functions from global scope 2026-06-07 08:48:20 -04:00
Eman Resu
6bd71d7e08 pkgs.formats.hcl1: host let variables to outside function scope 2026-06-07 08:48:18 -04:00
Eman Resu
01d76243e0 pkgs.formats.nixConf: host let variables outside of function scope 2026-06-07 08:48:10 -04:00
Eman Resu
5e0e1a165a pkgs.formats.elixirConf: host variables to outside function 2026-06-07 08:48:09 -04:00
Eman Resu
a13dd134c1 pkgs.formats.elixirConf: hoist let variables above args 2026-06-07 08:48:09 -04:00
Eman Resu
02c3f8ed7b pkgs.formats.keyValue: do more logic before generation
Allows more caching if the same generator is called multiple times.
2026-06-07 08:48:09 -04:00
Eman Resu
bffa9f19fb pkgs.formats.cdn: remove no-op merge
The json format only contains `type` and `generate` attributes, so
merging replaces both of them.
2026-06-07 08:48:09 -04:00
Eman Resu
e7ba7a958b pkgs.formats.toml: remove unused callPackage arg 2026-06-07 08:48:08 -04:00
Eman Resu
4cf86ef3bf pkgs.formats.gitIni: remove unused variable 2026-06-07 08:48:08 -04:00
Eman Resu
8217bcabaf pkgs.formats.ini: add helper to coerce all lists more lazily
Before, we would run a mapAttrs on every attribute, checking listToValue
on each of them. But listToValue is known ahead of time. Instead, we can
only run that map if listToValue isn't null in the first place.
2026-06-07 08:48:08 -04:00
Eman Resu
3198ae073a pkgs.formats.ini: rename list coercion helper
It coerces lists, it doesn't turn other attributes into lists.
2026-06-07 08:48:08 -04:00
Eman Resu
cc2394d9fa pkgs.formats.ini: share ignoredArgs between ini generators 2026-06-07 08:48:08 -04:00
nixpkgs-ci[bot]
f3fe341d1f Merge master into staging-nixos 2026-06-06 00:45:45 +00:00
Yuriy Taraday
1cc9c0cf12 pkgs-lib/formats: Use .attrs.json directly for TOML
A spinoff from https://github.com/NixOS/nixpkgs/pull/524404.
Add `--unwrap` argument to json2x, just like json2yaml has.
2026-06-05 15:50:45 +02:00
Yuriy Taraday
691dc02df0 pkgs-lib/formats: Use .attrs.json where possible
This expands on https://github.com/NixOS/nixpkgs/pull/498928 that
introduced __structuredAttrs here by actually using data in
`.attrs.json` when it makes sense, instead of relying on environment
variables. This leads to less temporary files, faster execution and
nicer code.
2026-06-04 19:21:52 +02:00
zowoq
1859a1a77c pkgs-lib/formats: use buildPackages for json2x 2026-05-30 13:50:27 +10:00
figsoda
701d8bd46b pkgs-lib/formats: reimplement toml.generate with Rust 2026-05-28 12:07:54 -04:00
Eman Resu
3740ca5732 formats.toml: don't merge with json format 2026-05-24 18:39:56 -04:00
André Lima
cf5266fbda pkgs-lib/formats: fix tests 2026-05-13 20:05:36 +01:00
K900
cd9a5eeafb Merge remote-tracking branch 'origin/staging-next' into staging 2026-05-04 21:37:41 +03:00
figsoda
331c7d8e30 pkgs-lib/formats: revert to remarshal for toml 2026-05-04 12:13:42 -04:00
K900
32048025b4 Merge remote-tracking branch 'origin/staging-next' into staging 2026-04-22 15:27:12 +03:00
phaer
e23ad3bd27 pkgs-lib/formats: switch toml generator from yj to go-toml (jsontoml)
Fixes NixOS/nixpkgs#511970, sclevine/yj#52.

Replace yj with go-toml's jsontoml for JSON-to-TOML conversion.
Update tomlAtoms expected output for go-toml's literal-string style.
2026-04-22 12:17:40 +02:00
Stefan Frijters
d67bdb69d1 pkgs-lib/formats: use structuredAttrs instead of passAsFile 2026-04-19 16:21:00 +02:00
zimbatm
7b2c5ede9a pkgs-lib/formats: use yj instead of remarshal for toml.generate
`remarshal` is a Python application; evaluating its derivation forces a
large slice of `python3Packages` (rich, ruamel-yaml, cbor2, tomlkit and
their transitive build/check inputs — ~150 distinct python-modules,
~2700 derivations). 95 NixOS modules use `formats.toml`, so any system
enabling one of those services pays this on every `nixos-rebuild`.

`yj` is a small Go binary that does the same JSON→TOML conversion. For
all values accepted by `(formats.toml{}).type` the output is
semantically identical (verified via `tomllib`).

Reproducer (best of 3, `NIX_SHOW_STATS=1 nix-instantiate -E
'(pkgs.formats.toml{}).generate "x" {a.b=1;}'`):

                        cpuTime  nrFunctionCalls   nrThunks  drv-closure
    before (remarshal)    0.69s          634,117  1,184,499   2722 paths
    after  (yj)           0.36s          271,308    566,981   1481 paths
                           -49%             -57%       -52%         -46%

Runtime closure of the converter: remarshal 202.3 MiB → yj 5.2 MiB.

Differences in output:
- yj emits intermediate table headers for deeply-nested keys (`[a]`
  `[a.b]` `[a.b.c]` rather than just `[a.b.c]`). Valid TOML, parses
  identically.
- yj renders very small/large floats as decimals rather than scientific
  notation (`1e-300` → 300-digit literal). Valid TOML, parses
  identically.
- Direct callers of `generate` that pass `null` (which the format type
  already rejects) get key-dropped instead of a build-time error.
  NixOS modules are unaffected since the option type filters this at
  eval time; several modules already `filterAttrs (v: v != null)` for
  exactly this reason.

Tested:
- `nix-build pkgs/pkgs-lib/tests -A formats` passes
- arrays of tables, nested tables, string escaping, int64, unicode
  keys/values, mixed scalar+table siblings round-trip through `tomllib`
  identically to remarshal output
2026-04-16 14:43:33 +02:00
Arian van Putten
0099ab9117 pkgs-lib/formats: add hcl1 format 2026-02-27 11:37:45 +01:00
Johannes Kirschbauer
c988f82f7a lib/types: add types.{json,toml} from pkgs.formats 2026-01-20 21:26:05 +01:00
Johannes Kirschbauer
cbcce89d8c pkgs/formats: toml format type is not nullable 2025-12-18 13:56:23 +01:00
nixpkgs-ci[bot]
a9cd171877 Merge master into staging-next 2025-10-17 00:16:42 +00:00
Felix Bühler
6ef6063ef6 pkgs.formats.plist: init (#448839) 2025-10-16 19:28:50 +00:00
nixpkgs-ci[bot]
bff70f3185 Merge master into staging-next 2025-10-13 12:07:07 +00:00
Arian van Putten
d1493eb6df pkgs-lib/formats/systemd: make format a function (#448460) 2025-10-13 11:16:24 +00:00
h7x4
fa6b7ec3d4 pkgs-lib/formats/systemd: make format a function 2025-10-13 20:11:40 +09:00
Sizhe Zhao
948a89c96b pkgs.formats.plist: init 2025-10-06 00:53:31 +08:00
h7x4
f2636ab940 pkgs-lib.formats: add missing parameter comment for mkStructuredType 2025-10-05 23:28:56 +09:00