The Nix Language versus the NixOS Module System
If you are configuring NixOS, it behooves you to understand the difference between the Nix language (hereafter: Nix) and the NixOS module system (hereafter: NMS). This is a confusing topic because they are closely related:
- NMS is implemented in, and configured using, Nix.
- Many of the same things are possible in both.
- You can 80% get away with using the Nix way of doing things when you should be using NMS, but that 20% will bite you.
Here is a cheatsheet, with explanations below:
Feature | In Nix | In NMS |
---|---|---|
Merging | attrs1 // attrs2 |
lib.mkMerge [ attrs1 attrs2 ]
|
If-then |
|
lib.mkIf cond values
|
If-then-else | if cond then v1 else v2 |
lib.mkMerge [ (lib.mkIf cond v1) (lib.mkIf (!cond) v2) ] |
Imports | import ./file.nix |
imports = [ ./file.nix ];
|