Nix is a purely functional package manager that also enables reproducible development environments.
The Linux distro NixOS comes with Nix pre-installed. You can Install Nix manually on other platforms.
Nix is a purely functional package manager that also enables reproducible development environments.
The Linux distro NixOS comes with Nix pre-installed. You can Install Nix manually on other platforms.
nixpkgs (https://github.com/NixOS/nixpkgs) is a monorepo containing a collection of Nix packages. It also includes various utility Nix functions (like writeShellApplication
), as well as the NixOS Linux distribution (including the Module System).
nix-darwin brings NixOS like configuration to macOS, allowing you to install packages (among doing other things) purely through Nix.
nix repl
starts an interactive environment for evaluating Nix expressions
Nix is supported on macOS.
Use Nix to manage your user environment.
Why opt for Nix when developping a software project instead of language-specific alternatives (such as Stack or GHCup for Haskell)?
home-manager
to manage dotfiles, packages, services
Sridhar Ratnakumar will demonstrate using Nix to declaratively manage your dotfiles, programs and services using home-manager, thus replacing the likes of legacy software like homebrew. The goal is to create an one-click environment to setup an user environment on any system, be it a Macbook or a Linux machine.
Tips on using Nix:
Ever since I first started using Nix for development, I have enjoyed the simplicity of setup: nix develop
, make the code change and see it work. That’s all well and good, but when your project keeps growing, you need to depend on external services like databases, message brokers, etc. And then, a quick search will tell you that docker is the way to go. You include it, add one more step in the setup guide, increasing the barrier to entry for new contributors. Not to mention, eating up all the system resources* on my not so powerful, company-provided MacBook.
The goal of this mini-tutorial is to introduce you to Nix the language, including flakes, as quickly as possible while also preparing the motivated learner to dive deeper into the whole Nix ecosystem. At the end of this introduction, you will be able to create a flake.nix that builds a package and provides a developer environment shell.
If Nix throws an error like:
NixOS is a Linux distribution based on the Nix package manager.
While package management is the key purpose of Nix, its derivations can also be used to produce non-package types, such as development environments (aka. “devShell”).
The directory used by Nix to store store paths (including derivations).
A list of currently available Nix jobs.
The nixpkgs library provides a module system for Nix expressions. To learn it, see our tutorial: Introduction to module system.
Using the module system is a key stepping stone to writing maintainable and shareable Nix code. In this tutorial, we’ll write a configuration system for the simple lsd command, thus introducing the reader to the Nix module system, so that they benefit from features such as configuration type checking, option documentation, and modularity. To learn more about the module system, we recommend this video from Tweag as well the article “Module system deep dive” from nix.dev.
Whethere you are on macOS or NixOS, you can install and setup fonts in an unified fashion with Nix using home-manager.
disko
disk partitioning
In this second tutorial, we will walk you through the process of installing NixOS. Unlike the first installation tutorial, we will use the command line to install NixOS manually, except for using disko to specify disk partitions declaratively in Nix itself. This is the first step toward our next tutorial, where we will automate the entire installation process.
[!tip] Nix language These *.nix
files are written in the Nix language.
Install Nix using the unofficial installer:*
Nix expressions are evaluated to produce derivations (among other values). These derivations when realized usually produce the compiled binary packages. Sometimes, realizing a derivation can produce a Nix expression representing another derivation. This generated Nix expression too needs to be evaluated to its derivation before it can be realized. This secondary evaluation is achieved by import
ing from the derivation being evaluated, and is called “import from derivation” or IFD.
Nix can behave unexpectedly in certain cases.
Git can be declaratively configured in Nix via home-manager. Here is an example:
Sridhar Ratnakumar will demonstrate the delights of using Nix to develop Rust as well as Haskell projects without needing to do any manual global setup on your system. We’ll start from a pristine macOS machine as well as a pristine Linux machine to get our development environment up and running in no time, all the way up to LSP support in VSCode.
Flakes is a necessary abstraction of top of Nix that improves on usability and reproducibility. Flakes is production ready despite being marked as experimental.
Nix derivations are instructions (recipes) for building a Nix package.
A binary cache provides cached binaries of built Nix Derivation.