This is a (work-in-progress) series of articles on the Nix ecosystem. Some things planned for the near future are development environments with Nix and direnv, many NixOS related things, and much more. Stay tuned by giving me a follow for when those come out!
A quick introduction to Nix
From the NixOS website, Nix is a tool that takes a unique approach to package management and system configuration. This "unique approach" refers to building packages in isolation from each other, ensuring that if packages work on one machine, they will work on another. This is done in a declarative fashion, essentially meaning that you tell Nix what to do, and it does it for you, without you having to tell Nix how to do it.
This is done using the nix language, which is a purely functional programming language purpose-built to configure the Nix package manager. The language is simple, dynamically typed, and purely functional. You'll pick it up quite easily, but if you want some formal learning, you can check out the Nix Language Basics chapter of the Nix documentation.
Here's a very simple "Hello, world!"
in Nix:
"Hello, world!"
Save it as hello.nix
and run it with the command (if you have Nix installed) nix eval --file hello.nix
to see Hello, world!
output to your terminal!
This works because every .nix
file contains a nix expression, which are functions, lists, attribute sets (dictionaries), numbers, paths, strings, etc. The nix eval
command evaluates the expression and prints it to the screen.
The Nix language is used to create packages for the nix ecosystem. Nix packages, as described earlier, are built in isolation from each other, ensuring that there is no dependency hell and allows multiple versions of a package to seamlessly coexist at the same time. Nix packages are derivations: "a specification for running an executable on precisely defined input files to repeatably produce output files at uniquely determined file system paths". Nix also provides useful builtin functions and a standard environment to make packaging easier. These packages can then be shared, like any other file, and built by other people without any hassle, since Nix guarantees reproducibility. A collection of 120,000+ packages is available in the nixpkgs repository.
Atop all this is the Nix Operating System, or NixOS. NixOS brings all of the declarative goodness of Nix into a Linux distribution. This means that (almost) everything about your system is declarative, including the packages (obviously), the users, the desktop, the login manager, systemd units, containers, and among other things, even the bootloader! Through some extensions, you can also partition disks, build images, and even configure your home folder. A single NixOS configuration is built into multiple pre-configured operating systems using just a single command!
Planned Articles
You can see a very crude list of planned articles for this series on GitLab. The GitLab repository will also contain any source code and large code snippets (not inlined) used in the series.
Support me
Here are some ways you can support me on this journey:
Thank you so much!
This upcoming series will explore a lot of what Nix can do, and what its amazing community has enabled it to do, so stay tuned for more articles in the near future!
Top comments (1)
lol excellent meme