Nix – A One Pager
github.com
github.com
Hah, I wonder why I didn't come across it before.
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).
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.
One upside is that because it's hard to write complex programs in nix, people don't do it (unless really needed). So the nixos tutorials and configuration examples on the internet are usually pretty simple. This is good for beginners, and nixos is already a huge undertaking.
With lisp I'm sure many of us would get crazy with abstractions.
Those constraints are really important for the rest of the Nix ecosystem to work.
[1]: technically there is one side effect - putting a derivation (i.e. a recipe for how to build a package) into the nix store.
The Nix language is designed for conveniently creating and composing derivations – precise descriptions of how contents of existing files are used to derive new files. It is a domain-specific, purely functional, lazily evaluated, dynamically typed programming language.
So, its key features are:1. domain-specific: designed for conveniently creating and composing derivations. This reason alone already justifies a new language, or an embedded domain-specific language (embedded in the Guile/Scheme for guix), or a mix of both (Starlark, the build language of Bazel embedded in a restricted Python-variant).
2. purely functional: this underlies the philosophy of the Nix package manager, which aims to be purely functional (also known as hermeticity in other build systems, such as Bazel). Being purely functional in turn underlies the congruence of the NixOS operating system, where you declare what the state the system should be in (as opposed to being convergent, so that you specify how to achieve the desired state).
3. lazily evaluated: similar to other build systems (including Bazel), so that you can build only what you need on demand.
4. dynamically typed: this one is controversial. Being dynamically typed—in other words, not developing a type system—gets Nix out of the door 20 years ago. But users often complain about the lack of proper types and modularity. There are experiments to add a type-and-contract system to Nix, such as Nickel (https://github.com/tweag/nickel).
Most of the above are also listed in the Overview of the One Pager.
How is using (nix?) standard library something that you don't want?
The next question is why is the Nix package manager needed and why should a software developer care. I don't know the answer.
Simply put, with Nix I can do:
nix run github:project/name
to run a program. Not many other package managers are capable of that.1. their home environments: for packages (some reach for brew on MacOS) and configurations (dotfiles, and some reach for stow).
2. their development shells: for build dependencies (compilers, SDKs, libraries), tools (LSP, linters, formatters, debuggers), and services (runtime, database). Some reach for devcontainers here.
3. or even their operating systems: for development, for CI, for deployment, or for personal use.
Nix provision all of the above in the same language, with Nixpkgs, NixOS, home-manager, and devShells such as https://devenv.sh/. What's more, Nix is (https://nixos.org/):
- reproducible: what works on your dev machine also works in CI and in prod,
- declarative: you version control and review your configurations and infrastructure as code, at a reasonable level of abstraction, to specify what the system should be, not how to get there,
- reliable: all changes (switching generations or profiles) are atomic with easy roll back.
Guix shows that it's possible to use a different frontend language technically, but switching the nixpkgs repo itself over to anything else at this point would be an enormous community effort where it's hard to say whether it's worth it.
> No, NixOS is a Linux distribution that utilizes these
My mistake!
NixOS is just a barebones Linux distro which uses the nix package manager for system configuration
Recently some Linux hobbyists new to the Nix community have started using the word 'Nix' to refer to NixOS, which is wrong and has understandably led to quite some confusion. I wish they'd stop fucking it up.
That is, The Nix Package Manager can be used independently of NixOS or The Nix Programming Language to install software on any Linux system (or MacOS) from the Nix Package Repository (search it at: https://search.nixos.org/packages) regardless of any knowledge (or any lack of knowledge!) that a given user has (or doesn't have!) of the Nix Programming Language...
Here's how to install it on a non-NixOS system (top half of page):
(Basically just "$ sh <(curl -L https://nixos.org/nix/install) --daemon" for multi-user setup, or "$ sh <(curl -L https://nixos.org/nix/install) --no-daemon" for single-user setup...)
The idea of running another Linux distro's package manager/installer to install things from their repository onto your Linux distro is not a new one -- in fact, it has been done rather successfully on many Linux distros for some time...
This concept invariably brings us to Bedrock Linux, a distribution whose sole purpose is to run package managers/installers -- from other distros!
https://bedrocklinux.org/index.html
...Or at least attempt to!
That's because some distros/package managers/Linux software -- may create conflicts with other installers/package managers/Linux software...
As can be seen here, from these Bedrock compatibility charts/"compatibility matrices":
https://bedrocklinux.org/0.7/distro-compatibility.html
https://bedrocklinux.org/0.7/feature-compatibility.html
Still, if not perfect in the current day, the idea of being able to mix-and-match package managers/installers from multiple Linux distros/repositories -- is a very compelling one!
Both the Nix and the Bedrock teams should be highly lauded for their efforts! Nix to create hermetic software environments, Bedrock to mix-and-match (and sort out compatibility issues!) between multi distro package managers/installers and software repositories...
Both are worth a serious look -- and potentially some of your time!