I’m exploring ideas for improving Nix’s interoperability with other languages and wanted to check if something like this already exists (or has been proposed).
The Problem
Nix natively supports JSON parsing (builtins.fromJSON), but not YAML. The common workaround is:
-
Define a derivation that converts YAML to JSON (e.g., using
yq) -
Use Import-From-Derivation (IFD)
-
Call
builtins.readJSONon the result
This works, but has some drawbacks:
-
The converted JSON ends up in the Nix store unnecessarily
-
For large YAML files, the entire file must be processed even if you only need a small part of it
-
IFD blocks evaluation and doesn’t parallelize well
The Idea
What if Nix could connect to a sandboxed external daemon and query it for lazily-evaluated Nix expression values?
The daemon would be provided by an external process (written in any language), and Nix would send requests like:
-
builtins.typeOfon a value -
Attribute access like
a.b.c -
Other operations that force evaluation
The daemon would then return the result as a Nix value, evaluating only the requested parts lazily.
For the YAML example: instead of converting the entire file to JSON via IFD, Nix could query a YAML-parsing daemon for just config.services.nginx.enable, and the daemon would parse only what’s needed and return the Nix value directly.
This would enable:
-
Parsing arbitrary formats (YAML, TOML, XML, etc.) lazily without IFD or polluting the Nix store
-
Better interop between Nix and other languages sharing the same Nix store
-
External processes providing “virtual” Nix values that are computed on-demand
Questions
-
Does something like this already exist in Nix?
-
Has this been proposed before in an RFC or GitHub issue?
-
Would this kind of extension mechanism be feasible within Nix’s architecture?
Any pointers would be appreciated!