Flakes: Difference between revisions
imported>SjLambda Cleaned out introductory language, mostly style. |
imported>SjLambda cleaned up the basic section, made it clearer |
||
| Line 1: | Line 1: | ||
'''Nix flakes''' is an [https://nixos.org/manual/nix/stable/contributing/experimental-features.html experimental feature] of the Nix package manager. | '''Nix flakes''' is an [https://nixos.org/manual/nix/stable/contributing/experimental-features.html experimental feature] of the Nix package manager. * Flakes was introduced with Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html see release notes]). | ||
== Introduction == | ====Introduction==== | ||
Flakes is a feature of managing Nix packages to simplify usability and improve reproducibility of Nix installations. Flakes manages dependencies between Nix expressions, which are the primary protocols for specifying packages. Flakes implements these protocols in a consistent schema with a common set of policies for managing packages. | Flakes is a feature of managing Nix packages to simplify usability and improve reproducibility of Nix installations. Flakes manages dependencies between Nix expressions, which are the primary protocols for specifying packages. Flakes implements these protocols in a consistent schema with a common set of policies for managing packages. | ||
| Line 12: | Line 12: | ||
* Flakes also allow for locking references and versions that can then be easily queried and updated programmatically. | * Flakes also allow for locking references and versions that can then be easily queried and updated programmatically. | ||
* [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html Nix command-line interface] accepts flake references for expressions that build, run, and deploy packages. | * [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html Nix command-line interface] accepts flake references for expressions that build, run, and deploy packages. | ||
== Enable flakes == | ====Enable flakes temporarily==== | ||
When using any <code>nix3</code> command, add the following command-line options: | |||
<syntaxHighlight lang=text> | |||
= | --experimental-features 'nix-command flakes' | ||
</syntaxHighlight> | |||
=== | ====Enable flakes permanently in NixOS==== | ||
Add the following to the [https://nixos.wiki/wiki/Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration] ([https://nixos.wiki/wiki/Flakes#Using_nix_flakes_with_NixOS flakes]): | |||
Add the following to | |||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
| Line 32: | Line 28: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
==== Other Distros | =====Other Distros, with Home-Manager===== | ||
Add the following to your home-manager config: | |||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
| Line 43: | Line 39: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
==== Other Distros | =====Other Distros, without Home-Manager===== | ||
{{ | {{Note | The [https://github.com/DeterminateSystems/nix-installer Nix Determinate Installer enables flakes by default.}} | ||
Add the following to <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code>: | Add the following to <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code>: | ||
| Line 53: | Line 49: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Basic | ===Basic Usage of Flake=== | ||
Before running any nix commands at this point, please note the two warnings below: one for encryption and the other for git. | |||
====Encryption WARNING==== | |||
{{Warning | Since contents of flake files are copied to the world-readable Nix store folder, do not put any unencrypted secrets in flake files.}} | |||
====Git WARNING==== | |||
For flakes in git repos, only files in the working tree will be copied to the store. | For flakes in git repos, only files in the working tree will be copied to the store. | ||
| Line 64: | Line 63: | ||
See also https://www.tweag.io/blog/2020-05-25-flakes/ | See also https://www.tweag.io/blog/2020-05-25-flakes/ | ||
====Generate flake.nix file==== | |||
To start the basic usage of flake, run the flake command in the project directory: | |||
<syntaxHighlight lang=text> | |||
nix flake init | |||
</syntaxHighlight> | |||
== Flake schema == | == Flake schema == | ||