132 Commits

Author SHA1 Message Date
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
isabel c06c7892c1 formats.toml: don't merge with json format (#523802) 2026-05-26 21:15:50 +00:00
zimbatm edb4b053f5 pkgs.formats.javaProperties: use lib.sources.sourceByGlobs
Uses the cleaner expression
2026-05-26 21:49:00 +12: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
phaer 32c7a5e046 pkgs-lib/formats: add regression tests for toml generator
Add two shouldPass tests that catch known yj regressions:

- tomlHeterogeneousArray: arrays mixing scalars and attrsets crash yj
  with 'unexpected primitive type' (NixOS/nixpkgs#511970)

- tomlCommaInKey: keys containing commas are silently truncated
  because yj stores TOML keys in Go struct tags where commas are
  option separators (sclevine/yj#52)

Expected values are taken from go-toml's jsontoml output.
Both tests fail under the current yj backend.
2026-04-22 12:17:33 +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
Dyego Aurélio 28096cc5e3 treewide: apply nixfmt 1.2.0 2026-01-22 18:37:56 -03: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
jopejoe1 6a11d4a70b tests.pkgs-lib: expose the tests included in it 2025-12-08 12:01:06 +01:00
uku 21e7ccb126 formats.javaProperties: fix cross-compilation 2025-12-06 17:54:57 +01:00
nixpkgs-ci[bot] 03e8920ce4 Merge master into staging-next 2025-10-17 18:05:18 +00:00
Sizhe Zhao 6f8bb63800 pkgs.formats.plist: don't test path
Reference: https://hydra.nixos.org/build/310233987/nixlog/1/tail
2025-10-17 21:40:19 +08: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
h7x4 8fd6252153 pkgs-lib.formats: move mkStructuredType to let-block 2025-10-05 23:28:51 +09:00
Felix Buehler c5cdad7dd4 pkgs-lib.formats: add mkStructuredType 2025-10-05 11:47:35 +02:00