This readme provides documentation for the nix code.
The target audience includes current and future maintainers.
Start with the comments inside the flake then continue reading here.
Note how every single nix file in this repository (with the exception of flake.nix
) has the same format:
{ inputs, cell }: ...
There is no escaping this.
A description of the arguments follows:
-
inputs.self
This is a path pointing to the top-level of the repository.
It is the only way to reference source files inside the repository.
Example:{ src = inputs.self + /plutus-core; }
-
inputs.cells
Provides access to all cells.
Remember that a cell is named after its folder.
The full format is:inputs.cells.<cell>.<cell-block>.value
.
Examples:inputs.cells.plutus.packages.read-the-docs-site
inputs.cells.plutus.devshells.plutus-shell
inputs.cells.plutus.library.agda-packages
-
inputs.<flake-input>
The flake inputs proper.
Examples:inputs.std
,inputs.nixpkgs
,inputs.sphinxcontrib-haddock
-
cell.<cell-block>
Provides access to the cell's blocks.
This is a shorthand forinputs.cells.<cell>.<cell-block>
, where<cell>
evaluates to the cell housing this nix file.
Examples:cell.library.agda-packages
only works for code in/cells/plutus
Alternativelyinputs.cells.plutus.library.agda-packages
works everywherecell.packages.hlint
only works for code in/cells/plutus
Alternativelyinputs.cells.plutus.packages.hlint
works everywhere
To enforce further discipline, we enact a one-derivation-per-file policy.
This is currently applied without exception.
This means that every single nix file in this repository is either:
- A
default.nix
cell block importing and thus grouping all files in its folder - A
<cell-block>.nix
cell block exporting an attrs with a single derivation - A file evaluating to a single derivation
Further, we enforce that the nix fragment name be equal to the file name.
This means that if one looks at the fully expanded structure of the cellsFrom
folder, one will conclude that there are exactly as many fragments as there are nix files (excluding the default.nix
files, which again merely act as a grouper for the cell block).
Finally this means that for each nix file some-fragment.nix
, one can run:
nix (develop|build|run) .#some-fragment
That is unless the relevant cell block was not exposed in flake.nix
.
Note however that the one-derivation-per-file policy stated above only holds for the packages
and devshells
cell blocks.
Other cell blocks (for example library
or pipelines
) host nix files that evaluate to functions, literal values, or more complex attribute sets.
While these blocks are not exposed directly to the flake (they are not "harvested"), they can still be accessed using this syntax:
nix (develop|build|run) .#<system>.<cell>.<cell-block>.<valid.attr.path>
For example:
nix run .#x86-64-darwin.plutus.library.agda-project.hsPkgs.Agda
As an example, consider the file ./nix/cells/plutus/packages/eutxo-paper.nix
:
./nix/cells
is thecellsFrom
value inflake.nix
/plutus
is the cell name/plutus/*
are accessible viacell.*
from{ inputs, cell }
(while insidecells/plutus
)/plutus/*
are accessible viainputs.cells.plutus.*
(everywhere)/packages
is the cell block name/packages/*
are accessible viacell.packages.*
(while insidecells/plutus
)/packages/*
are accessible viainputs.cells.plutus.packages.*
(everywhere)/eutxo-paper.nix
contains a single derivationeutxo-paper
is the name of the flake fragment- A derivation named
eutxo-paper
is accessible viacell.packages.eutxo-paper
(while insidecells/plutus
) - And also accessible via
inputs.cells.plutus.packages.eutxo-paper
(everywhere) - And also buildable via
nix build .#eutxo-paper
As another example, consider the file ./nix/cells/plutus/library/default.nix
./nix/cells
is thecellsFrom
value inflake.nix
/plutus
is the cell name/plutus/*
are accessible viacell.*
from{ inputs, cell }
(while insidecells/plutus
)/plutus/*
are accessible viainputs.cells.plutus.*
(everywhere)/library
is the cell block name/library/*
are accessible viacell.library.*
(while insidecells/plutus
)/library/*
are accessible viainputs.cells.library.devshellCommands.*
(everywhere)/default.nix
imports every file in its directory/default.nix
contains a derivation for each file in its directory- Each attrs field in
/default.nix
is named after the file it imports (minus the.nix
)