Hacker News new | ask | show | jobs
by aidanhs 807 days ago
Can you elaborate on what you're getting at?

Syntax-wise it's about as similar to JSON as Erlang expressions are (i.e. superficially similar in some cases).

Semantics-wise I've personally found any superficial similarity to JSON to be actively unhelpful in understanding because of some important processing differences (e.g. paths, laziness).

3 comments

The FunctionalScript language is supposed to be a superset of JSON and a subset of Javascript that's pure and functional. Not sure that's suited to the use case Nix is going for, but that sounds like what we'd get if we took the extended-JSON path.
JSON is not a language, it's a data representation. Nix data is equivalent to JSON, except Nix also has a "path" datatype.
First a minor quibble: if you're talking about 'Nix data', then starting the conversation by talking about 'Nix-the-language' is rather misleading.

That aside, Nix allows you to create infinite datastructures, e.g.

    $ nix eval --expr 'rec { z = { a = z; i = 5; }; }.z.a.a.a.i'
    5
which you can't do with JSON.

But even if JSON did have some way of handling datastructure 'loops', it's still not helpful because of laziness. You almost never want to eagerly evaluate a Nix expression to produce what you seem to term 'Nix data', because you'll invoke the `derivation` built in function to create paths you never actually reference - this is why laziness is such an important property of Nix.

So I'm still not clear what user-facing part of Nix is isomorphic to JSON. If it's just "Nix types [0] are similar to JSON types" then...sure.

[0] https://nixos.org/manual/nix/stable/language/values

Agreed. I've tried to write a json-nix converter (because I wanted to try configuring my system in jsonnet) and it's absolutely not easy, or obvious how to do this.