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.
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.
- Creating Reproducible executables with Nix enabling to execute with one script only requiring the package manager.
- How the build process works along with Nix derivations.
- The new way to manage channels with Nix flakes.
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.
- If you want an introduction to Nix, the Nixology video series is a great primer starting with this video. You don't have to watch through the whole playlist but it also gives practical starter points such as demystifying Nixpkgs and the standard library which you'll need you know once you've started packaging with Nix. I really recommend this series, it's pretty great!
-
If you're decided to go with NixOS, the first few chapters of the official manuals are great and extensive. A good first reading section after installation is how to administer your NixOS installation and its package management process.
- I have difficulty grokking the manual but thankfully a fellow newcomer wrote a document listing the terminologies helping me absorb the material (big thanks to Stéphan Kochen for the writing).
- Take a look at others' NixOS config and see how they did it. For other examples, you can take a look at my config and the inspiration behind my config (except his' is on the edge of the bleeding edge).
- If you want to keep up-to-date with the community, you might want to hang out in the official forum.
If you want realtime help, you can go to the IRC channel
#nix
atlibera.chat
. The Nix community knows that its documentation is lagging so they're pretty open to newbies asking for help that could've been easily missed. -
What about if you're now comfortable with Nix (or NixOS) and now looking for more ways to use its power (i.e., packaging some applications)?
- The beloved Nix pills series and the nixpkgs manual is a great starting point especially if you're starting to contribute to the official package set.
- nix.dev and the unofficial Nix wiki are also great introductions to more Nix stuff with practical applications.
- Jon Ringer, one of the long-time Nix user and contributor, has a YouTube channel focused on Nix tutorials at beginners- and intermediate-level.
- If you want to look out for its future, the community arranges an annual event with talks all about Nix. In fact, as of 2020-11-03, a NixCon online conference has recently occurred with the event lasting for two days. They also archive their talks and whatnot on their YouTube channel.
At a glance, anyways. I'm not experienced enough with Go to say that with utmost confidence.