Flakes: Difference between revisions

imported>Doronbehar
Importing packages from multiple channels: Show another way to apply overlays
imported>Edrex
mention pure evaluation mode and the need for fetchurl to include sha256 arg
Line 28: Line 28:
In NixOS this can be achieved with the following options in <code>configuration.nix</code>.
In NixOS this can be achieved with the following options in <code>configuration.nix</code>.


===== System-wide installation =====
==== System-wide installation ====
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{ pkgs, ... }: {
{ pkgs, ... }: {
Line 40: Line 40:
</syntaxHighlight>
</syntaxHighlight>


===== Installation as an extra command =====
==== Installation as an extra command ====
Add command <code>nixFlakes</code> that serves as a flakes-enabled alias to the <code>nix</code> command.
Add command <code>nixFlakes</code> that serves as a flakes-enabled alias to the <code>nix</code> command.


Line 94: Line 94:
* <code>outputs</code> is a function of one argument that takes an attribute set of all the realized inputs, and outputs another attribute set which schema is described below.
* <code>outputs</code> is a function of one argument that takes an attribute set of all the realized inputs, and outputs another attribute set which schema is described below.


== Input schema ==
=== Input schema ===


This is not a complete schema but should be enough to get you started:
This is not a complete schema but should be enough to get you started:
Line 121: Line 121:
The bar input is then passed to the output schema
The bar input is then passed to the output schema


== Output schema ==
=== Output schema ===


This is described in the nix package manager [https://github.com/NixOS/nix/blob/master/src/nix/flake.cc src/nix/flake.cc] in CmdFlakeCheck.
This is described in the nix package manager [https://github.com/NixOS/nix/blob/master/src/nix/flake.cc src/nix/flake.cc] in CmdFlakeCheck.
Line 213: Line 213:
</syntaxHighlight>
</syntaxHighlight>


== Making your evaluations pure ==
Nix flakes run in pure evaluation mode, which is underdocumented. Some tips for now:
- fetchurl and fetchtar [require a sha256 argument](https://github.com/NixOS/nix/blob/36c4d6f59247826dde32ad2e6b5a9471a9a1c911/src/libexpr/primops/fetchTree.cc#L201) to be considered pure.


== The nix flakes command ==
== The nix flakes command ==