2022-04-28 00:25:33 +03:00
# Architecture
2020-11-24 15:38:12 +02:00
2022-04-28 00:25:33 +03:00
This chapter describes how Nix works.
It should help users understand why Nix behaves as it does, and it should help developers understand how to modify Nix and how to write similar tools.
2022-04-26 12:46:15 +03:00
2022-04-28 00:25:33 +03:00
## Overview
2022-04-27 22:17:44 +03:00
Nix consists of hierarchical [layers ](https://en.m.wikipedia.org/wiki/Multitier_architecture#Layers ).
```
2022-05-03 15:05:46 +03:00
[ commmand line interface ]--------+
| |
| evaluates | manages
V |
[ configuration language ] |
| V
+-------------------------------|---------------------------------+
| store | |
| | evaluates to |
| | |
| references V builds |
| [ build input ] --> [ build plan ] --> [ build result ] |
| |
+-----------------------------------------------------------------+
2022-04-27 22:17:44 +03:00
```
At the top is the *command line interface* , translating from invocations of Nix executables to interactions with the underlying layers.
2022-04-27 22:21:46 +03:00
Below that is the *Nix language* , a [purely functional ](https://en.m.wikipedia.org/wiki/Purely_functional_programming ) configuration language.
2022-04-25 14:25:43 +03:00
It is used to compose expressions which ultimately evaluate to self-contained *build plans* , used to derive *build results* from referenced *build inputs* .
2022-04-27 22:17:44 +03:00
::: {.note}
The Nix language itself does not have a notion of *packages* or *configurations* .
As far as we are concerned here, the inputs and results of a derivation are just data.
In practice this amounts to a set of files in a file system.
:::
The command line and Nix language are what users interact with most.
Underlying everything is the *Nix store* , a mechanism to keep track of build plans, data, and references between them.
It can also execute *build instructions* , captured in the build plans, to produce new data.