Flakes: Difference between revisions

imported>Jtojnar
describe flake-compat
imported>Patryk27
Rework the introduction
Line 1: Line 1:
Nix flakes is some upcoming feature in the Nix package manager.
'''Nix Flakes''' are an upcoming feature of the Nix package manager.
It allows to download nix expressions from other sources
in a declarative way by specifying them a flake.nix file.
Those sources are called flakes and also have a flake.nix
where they can describe their own dependencies.
Sources can be tarballs, git, local directories or mercurial repositories.
It makes evaluation reproducible with providing a lock called flake.lock.
This lock file provides hashes for sources and locks the revision
of external version control system.
Nix flakes intents to replace nix channels and the nix search path (<code>NIX_PATH</code>).


== Installing nix flakes ==
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'''.


Right now nix flakes are only available in the unstable nix version and need to be enabled in nix.conf as well.
=== 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 system install `nixUnstable` in your environment:
On non-nixos systems, install `nixUnstable` in your environment:


<syntaxHighlight lang=console>
<syntaxHighlight lang=console>