What language is the low level store derivation written in?

nix-build is said to be a wrapper of nix initialize, which translates a derivation in high level Nix expression to a low-level store derivation, and nix-store --realize, which builds the store derivation.

What language is the low level store derivation written in? Is it not Nix expression, but JSON?

Thanks.

1 Like

Looks like a valid Python expression :grin:

Some Nix commands (e.g. nix derivation show) will output the derivation as JSON but the .drv files are actually using ATerm language, see also Why was ATerms chosen for the format of store derivations instead of ASN.1? and the other linked thread there.

4 Likes

Thanks. Are both Nix-expression derivation and ATerm derivation stored in the Nix store? Or only the latter, which is why it is called “store derivation”?

1 Like

.drv file (aka store derivation) will appear in the store as a consequence of instantiating a derivation produced by evaluating a Nix expression. The derivation is more of a conceptual thing so it cannot exist in Nix store except serialized as store derivation.

.nix files containing Nix expressions (i.e. Nix code) could, in theory, also end up in Nix store but it is generally not the case. When using commands like nix-build, Nix will not copy any .nix files into the store unless Nix code itself forces it (for example, when path to a Nix file is used in string interpolation or a file is pulled in using a function like builtins.path). Though, the experimental flakes feature deviates from this: currently, Nix will copy a flake to the store before evaluating the Nix expressions within.

2 Likes