Commit Graph

54 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
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
Pol Dellaiera
29c66c6eaa pkgs.formats.configobj: init
Co-authored-by: Matt Sturgeon <matt@sturgeon.me.uk>
2026-06-16 20:58:27 +02:00
figsoda
701d8bd46b pkgs-lib/formats: reimplement toml.generate with Rust 2026-05-28 12:07:54 -04:00
figsoda
331c7d8e30 pkgs-lib/formats: revert to remarshal for toml 2026-05-04 12:13:42 -04: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
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
jopejoe1
6a11d4a70b tests.pkgs-lib: expose the tests included in it 2025-12-08 12:01:06 +01: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
Sizhe Zhao
948a89c96b pkgs.formats.plist: init 2025-10-06 00:53:31 +08:00
h7x4
5ca4c89bd4 pkgs-lib/pythonVars: add test 2025-09-18 18:15:57 +02:00
cinereal
c30b9ec953 formats: add nixConf
adds `nixConf` (to generate `nix.conf` files) as a file format to
`lib.formats`, and uses it for serializing `nix.settings`.

this makes it easier to 'manually' serialize `nix.settings`, which is
relevant in e.g. safely handling sensitive values such as that of
`nix.settings.access-tokens`.

Signed-off-by: cinereal <cinereal@riseup.net>
2025-09-06 13:25:52 +02:00
Vladimír Čunát
7186236235 formats tests: drop jdk8 and add default jdk
It was weird to keep testing an ancient version
but not test the default one.  Now jdk8 has issues:
https://hydra.nixos.org/build/301885710#tabs-buildsteps
2025-07-11 10:51:41 +02:00
Vladimír Čunát
26650e0d10 pkgs/pkgs-lib/tests/formats.nix: adapt to new style
https://hydra.nixos.org/build/300150957/nixlog/2/tail
Probably caused by f80b06e
2025-06-17 21:08:39 +02:00
Martin Weinelt
eb8f7fcc12 pkgs.formats.yaml_1_2: init
Same as YAML 1.1 but relies on the unpinned remarshal version which emits
YAML 1.2.
2025-06-11 17:39:36 +02:00
Silvan Mosberger
374e6bcc40 treewide: Format all Nix files
Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](8616af08d9/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
2025-04-01 20:10:43 +02:00
Matt Sturgeon
2611d5bd70 formats.lua: init
Add a lua format, based on `lib.generators.toLua`.
2025-03-19 21:18:49 +00:00
Silvan Mosberger
6c4b0e2858 pkgs-lib: Make tests independent of Nix file contents
Before, all of these tests would be rebuilt whenever formats.nix is
modified, but there's no need for this :)
2025-02-17 18:42:59 +01:00
Felix Buehler
a468405d67 pkgs-lib.formats.xml: init 2025-01-13 21:56:22 +01:00
uku
141f581d6f pkgs.formats: add cdn 2025-01-06 11:57:41 +01:00
Silvan Mosberger
4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00
Martin Weinelt
80a4fc03f0 pkgs/lib/formats: test more explicitly for YAML 1.1 compat 2024-11-09 23:33:37 +01:00
MithicSpirit
e14483d6a6 formats.ini: disable merging as list by default
Previously, setting listsAsDuplicateKeys or listToValue would make it so
merging these treat all values as lists, by coercing non-lists via
lib.singleton. Some programs (such as gamemode; see #345121), allow some
values to be repeated but not others, which can lead to unexpected
behavior when non-list values are merged like this rather than throwing
an error.

This now makes that behavior opt-in via the mergeAsList option. Setting
mergeAsList (to either true or false) without setting either
listsAsDuplicateKeys or listToValue is an error, since lists are
meaningless in this case.
2024-10-10 17:57:41 -04:00
nhnn
083f211783 pkgs: add PHP to formats.nix 2024-05-16 13:07:34 +03:00
benaryorg
8b2d86b982 pkgs.formats: toINIWithGlobalSection wrapper
The new format is based on the existing wrapper and generates an INI file with an unnamed global section at the top as is used by *stunnel* for instance.
Technically the INI format is a subset of this however testing, type checking, and API guarantees profit from two separate generators.

Co-authored-by: tim-tx <tim-tx@users.noreply.github.com>
Signed-off-by: benaryorg <binary@benary.org>
2024-02-12 17:58:48 +00:00
benaryorg
3e72e7c014 pkgs.formats: negative type checking tests
Tests using `shouldFail` (new) enable testing for whether the type system catches any unintended uses (missing parameters or unavailable data types in the format).
It should not be necessary to test for all possible outliers for each format, however format-specific tests (for instance those using a rigid submodule structure) can ensure that common mistakes err out instead of being silently discarded, while also allowing test-driven development of sorts.

Signed-off-by: benaryorg <binary@benary.org>
2024-02-12 16:56:09 +00:00
h7x4
b6cdfec16c formats.hocon: add tests 2024-02-09 16:40:22 +01:00
h7x4
18ca8b21e2 formats.libconfig: add tests
Co-authored-by: ckie <25263210+ckiee@users.noreply.github.com>
Signed-off-by: h7x4 <h7x4@nani.wtf>
2023-10-27 18:32:22 +02:00
K900
0782b000d9 pkgs-lib/tests/formats: fix expected output 2023-08-27 14:41:28 +03:00
Francesco Gazzetta
0d2842a435 formats.keyValue: add tests 2022-06-20 22:36:29 +02:00
Robert Hensing
3c10819ecf Merge pull request #167172 from hercules-ci/javaProperties-type-coercions
`formats.javaProperties`: add type coercions
2022-04-25 16:29:48 +02:00
zowoq
9233d33579 pkgs-lib.formats: fix tomlkit output 2022-04-18 17:14:55 +10:00
lassulus
d23b044959 tests formats: fix due to tomlkit output change 2022-04-10 09:06:11 -04:00
Robert Hensing
337c72b5cd pkgs.formats.javaProperties: Add type coercions
A usability improvement.
2022-04-04 14:24:15 +02:00
Robert Hensing
46156529f2 tests.pkgs-lib.formats: Allow strings with context in test runner 2022-04-04 14:22:22 +02:00
Robert Hensing
dcca8f5be2 tests.pkgs-lib.formats: Detect when impossible input is fed 2022-04-04 13:17:11 +02:00
Robert Hensing
9a0739cbe2 formats.javaProperties: Add comment 2022-04-01 15:19:45 +02:00
Robert Hensing
4f8e44394c formats.javaProperties: init 2022-04-01 15:19:45 +02:00
Silvan Mosberger
c511b4e1f9 formats: Fix yaml test
Faulty test result was introduced in https://github.com/NixOS/nixpkgs/pull/133807
2021-08-26 01:57:43 +02:00
lucasew
83514ae7a9 lib.formats.yaml: use well known YAML format
The way `(lib.formats.yaml {}).generate` generates YAML is compliant
because on YAML 1.2 spec JSON is a subset of YAML but it bugs people's
minds and can lead to problems with software that is not compatible with
YAML 1.2.

This commit also changes the test of the generation function. Data
validation/typing remains the same.

See #133802.

Signed-off-by: lucasew <lucas59356@gmail.com>
2021-08-25 14:02:59 +02:00
Robert Hensing
fbafeb7ad5 treewide: runCommandNoCC -> runCommand
This has been synonymous for ~5y.
2021-08-15 17:36:41 +02:00
Ben Wolsieffer
98336c223b pkgs-lib: allow paths in TOML, YAML and JSON
Paths get automatically added to the store. The INI generator currently chokes
on paths, so it is not supported for now.
2021-06-28 11:59:03 -04:00
Silvan Mosberger
b8336c2b8a formats.ini: Introduce listToValue argument (#121613)
Allows coercing lists to values. E.g.

  formats.ini { listToValue = lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault {}); }
2021-05-04 09:49:25 +02:00