Flakes: Difference between revisions
imported>Jtojnar describe flake-compat |
imported>Patryk27 Rework the introduction |
||
| Line 1: | Line 1: | ||
Nix | '''Nix Flakes''' are an upcoming feature of the Nix package manager. | ||
== Installing | Flakes allow you to specify your code's dependencies (e.g. remote Git repositories) in a declarative way, simply by listing them inside a <code>flake.nix</code> file: | ||
<syntaxHighlight lang=nix> | |||
{ | |||
inputs = { | |||
home-manager.url = "github:rycee/home-manager"; | |||
}; | |||
} | |||
</syntaxHighlight> | |||
Each dependency gets then pinned, that is: its commit hash gets automatically stored into a file - named <code>flake.lock</code> - making it easy to, say, upgrade it: | |||
<syntaxHighlight lang=console> | |||
$ nix flake update --update-input home-manager | |||
</syntaxHighlight> | |||
''(if you're familiar with modern packages managers like <code>cargo</code> or <code>npm</code>, then the overall mechanism shouldn't surprise you - Nix works in a similar way, although without a centralized repository.)'' | |||
Flakes are meant as a replacement for '''channels''' and things like ad-hoc invocations of <code>builtins.fetchgit</code> - no more worrying about keeping your channels in sync, no more worrying about forgetting about a dependency deep down in your tree: everything's at hand inside <code>flake.lock</code>. | |||
== Installing flakes == | |||
Currently flakes are available only in the '''unstable''' version of Nix and so they need to be explicitly enabled inside '''nix.conf'''. | |||
=== NixOS === | === NixOS === | ||
In NixOS this can be achieved with the following line in <code>configuration.nix</code> | In NixOS this can be achieved with the following line in <code>configuration.nix</code> | ||
| Line 28: | Line 40: | ||
=== Non-NixOS === | === Non-NixOS === | ||
On non-nixos | On non-nixos systems, install `nixUnstable` in your environment: | ||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||