Flakes: Difference between revisions

imported>Ajs124
update config for system-wide install and drop separate command
imported>Fricklerhandwerk
update installation methods
Line 35: Line 35:
Flakes replace the nix-channels command 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 right inside <code>flake.lock</code>.
Flakes replace the nix-channels command 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 right inside <code>flake.lock</code>.


== Installing flakes ==
== Using flakes ==


=== NixOS ===
Flakes have been introduced with Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html release notes]).
In NixOS this can be achieved with the following options in <code>configuration.nix</code>.
 
See [https://lazamar.co.uk/nix-versions/?channel=nixpkgs-unstable&package=nix Nix package versions] to find a channel or <code>nixpkgs</code> revision providing the required Nix version.


==== System-wide installation ====
===Temporary===
<syntaxHighlight lang=nix>
{ pkgs, ... }: {
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
}
</syntaxHighlight>


=== Non-NixOS ===
Add <code>--experimental-features 'nix-command flakes'</code> when calling the <code>nix</code> command.
On non-nixos systems, install <code>nixFlakes</code> in your environment:


<syntaxHighlight lang=console>
=== Permanent ===
$ nix-env -iA nixpkgs.nixFlakes
</syntaxHighlight>


Edit either <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code> and add:
Edit either <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code> and add:
Line 60: Line 53:
</syntaxHighlight>
</syntaxHighlight>


This is needed to expose the Nix 2.0 CLI and flakes support that are hidden behind feature-flags.
If the Nix installation is in multi-user mode, don’t forget to restart the <code>nix-daemon</code>.
 
=== NixOS ===
 
On NixOS set the following options in <code>configuration.nix</code> and run <code>nixos-rebuild</code>.


Finally, if the Nix installation is in multi-user mode, don’t forget to restart the nix-daemon.
<syntaxHighlight lang=nix>
{ pkgs, ... }: {
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
}
</syntaxHighlight>


== Basic project usage ==
== Basic project usage ==