4 ms·
The Nix syntax being complex is something that is taken for a given in online circles, but it's actually one of the most simple languages that I've learned. The
by soraminazuki 5y ago
The Nix syntax being complex is something that is taken for a given in online circles, but it's actually one of the most simple languages that I've learned. The Nix syntax is in essence just JSON with functions which consists of the following building blocks:
* Primitive values (strings, numbers, paths, booleans, null)
* Lists and sets
* Variables
* Functions
* Conditionals
* Assertions
* Arithmetic operators
And that's all there is. For people familiar with programming, it should only take around 10 minutes or so to grasp the syntax. It would take much, much longer for commonly used programming languages like C, C++, Javascript, Python, Ruby, Perl, ... you name it.
The official docs does a decent job at explaining the syntax[1]. I didn't have any experience with functional languages prior, but I didn't have much problem grasping the syntax once I've read through the documentation.
[1]: https://nixos.org/manual/nix/stable/#ch-expression-language https://nixos.org/manual/nix/stable/#ch-expression-language
- greatgib 5y agoIt is not necessary what it can do the problem, but how it does it. Looking at the page you link for example: https://nixos.org/manual/nix/stable/expressions/expression-syntax.html https://nixos.org/manual/nix/stable/expressions/expression-s... <<{ stdenv, fetchurl, perl }:>> << Nix functions generally have the form { x, y, ..., z }: e where x, y, etc. are the names of the expected arguments, and where e is the body of the function. >> Strange, but let's say ok. But then, in the example, where does the function end? Then, <<"So we have to build a package. Building something from other stuff is called a derivation in Nix (as opposed to sources, which are built by humans instead of computers). >> Looking at that, I say whaaaattt? "derivation" does not mean anything obvious to anyone used to build packages. And then, as the subtitle said, did they decide to use a weird name just to confuse everyone for the pleasure? Then: << A set is just a list of key/value pairs where each key is a string and each value is an arbitrary Nix expression. They take the general form { name1 = expr1; ... nameN = exprN; }. >> So, looking at the code, from far, function, sets, everything looks mixup ...
- soraminazuki 5y agoThe section you linked to was not specifically about syntax, but a high level overview that is explained in detail later on. For syntax, you should look at https://nixos.org/manual/nix/stable/expressions/expression-language.html https://nixos.org/manual/nix/stable/expressions/expression-l.... It should explain things like where how you write functions. > Looking at that, I say whaaaattt? "derivation" does not mean anything obvious to anyone used to build packages. And then, as the subtitle said, did they decide to use a weird name just to confuse everyone for the pleasure? The same kind of reaction can be made to any programming concept introduced in an introductory material. I don't think it's fair to ridicule Nix for defining its own technical terms, especially when the writing you referred to explains what it is. It is somewhat light on details, but you can't possibly expect an introductory section to explain it all at once. It should be enough to keep you going. But to answer your question, a derivation is the low-level build instruction that Nix's package builder can parse and build packages out of. You use the Nix language to convert high level package definitions to Nix derivations before feeding it to the package builders.