Components of a Nix derivation

The function derivation describes Nix derivations, taking a set whose attributes describe all the inputs of a build. mkDerivation wraps this function for convenience by setting system and using bash as the builder to which the builder attribute is passed as an argument.

A derivation comprises

  • a system attribute whose value is a platform identifier string like x86_64-darwin corresponding to the system on which the build takes place
  • a name attribute whose value is the name of the package
  • a builder attribute whose value is the program to be run to build the package (either a derivation or a path)
  • additional attributes for the builder, passed as environment variables:
    • String and numbers are passed in unchanged
    • Paths are copied to the Nix store and their store paths are placed in the variables
    • Derivations are built and their store paths are placed in the variables
    • Lists of the previous types are joined with spaces
    • true becomes "1", and false and null become ""
  • an optional list args of command line arguments to be passed to the builder
  • an optional list outputs specifying the outputs of a derivation


Specifying outputs = [ "lib" "headers" "doc" ] will produce three store paths, such that the builder can specify something like

./configure --libdir=$lib/lib --includedir=$headers/include --docdir=$doc/share/doc

Suppose we did this for Hello, Nix! Then we could specify build inputs in another derivation like

buildInputs = [ hello.lib hello.headers ]

or the equivalent

buildInputs = [ hello hello.headers ]

since the first element of outputs determines the default output.

Separating outputs this way allows us to download and garbage collect paths independently.