What is a derivation?
You can think of a derivation as a set of build instructions, somewhat similar to how IKEA furniture comes with an assembly manual. The furniture (or package, or configuration file, or...) still needs to be built, but the build instructions (the derivation) have the information on how to do so. Nix takes these instructions, and uses them to create a build result.
Derivations are described using the Nix language (nixlang), and they may build anything - it doesn't need to be a software package! You might have a derivation for every software package that is being a built, and a derivation for your system configuration, and a derivation for each (automatically generated) configuration file for the software on your system, and so on.
Derivations also keep track track of their dependencies; that is, which other derivations are referenced inside of its instructions. Nix needs this information to make sure that everything is built in the correct order, and correctly linked together.
There is a derivation
function in the standard library of Nix, but in practice you will probably never use it. Instead, you will most likely be using mkDerivation
, which is a wrapper function in nixpkgs that automatically handles some things for you. This is explained further in the chapter about nixpkgs.