wiki/notebook/tools.nix.org
Gabriel Arazas b088086b06 Merge evergreen notes into the notebook
Now, it's all under the notebook umbrella. Seems to be appropriate as it
is just my notes after all.

I also updated some notes from there. I didn't keep track of what it is
this time. Something about more learning notes extracted from my
"Learning how to learn" course notes and then some. Lack of time and
hurriness just makes it difficult to track but it should be under
version control already.
2021-07-21 16:28:07 +08:00

7.2 KiB

The basics of Nix package manager

Nix package manager is a great tool for reproducibility as you can easily set up your environment. Taking it up to the next level with NixOS, your whole installation.

Among other things, Nix also has the following features to look out for.

Ecosystem

The basic ropes into getting started with Nix.

  • nixpkgs is the official package set similar to Flathub for Flatpak. In terms of size, nixpkgs is comparable to AUR.
  • NUR is the user-contributed Nix packages curated by the community. While most of the packages can be passed into nixpkgs, most of them are niche packages (or the package author are not interested in maintaining it).
  • direnv has integration with Nix as well as a lot of editors.
  • lorri replaces nix-shell integrating with direnv.
  • niv provides a easier way to manage dependencies though it will be easier with Nix flakes.
  • /foodogsquared/wiki/src/commit/b088086b0695da8b50287b30e0665eff38435008/notebook/Nix%20flakes is an upcoming feature for Nix, replacing the traditional Nix channels into a decentralized set of derivations that can be retrieved from anywhere similar to Go modules 1.
  • Cachix is a cache service enabling to easily distribute binaries built with Nix.
  • DevOS is a configuration framework for deploying NixOS-based systems.

Components of the package manager

Holistically, Nix is made up of at least four components: the store, the language, the derivations, and the sandbox.

  • The store is a immutable centralized location where all of the outputs are placed.
  • The derivations are essentially build instructions.
  • The language (also called as Nix but we'll refer to it as Nixlang) is a domain-specific language for creating derivations.
  • The build process can be locked in a sandbox, improving the reproducibility of a setup and lowering the attack surface for a malicious package.

Overlays

You can override values in Nix as a way to customize nixpkgs. For example, if you want to use a different version from the nixpkgs channel, you can change the appropriate value.

let overlay = self: super:
      {
        ncmpcpp = super.ncmpcpp.override { visualizerSupport = true; };
      }

For another example, you can see some examples from Neovim and Veloren (which also uses Nix flakes).

You can set overlays automatically either by setting nixpkgs.overlays from your system configuration or ~/.config/nixpkgs/overlays/ folder for user-specific settings. You could also set overlays for standalone Nix code similarly through the overlays key — e.g., import <nixpkgs> ? { overlays = (self: super: { } ); };.

Opinionated guide to learn Nix

Nix throws a bunch of traditional concepts behind as well as pioneers a bunch of things creating a steeper learning curve. The official documentation for Nix is pretty great at covering ground of all Nix stuff which makes it good as a reference but horrible for a newbie who wants to gain a quick overview of what Nix is all about. So I'll list a bunch of resources that helped me becoming comfortable with the Nix thing.


1

At a glance, anyways. I'm not experienced enough with Go to say that with utmost confidence.