Flakes: Difference between revisions

imported>Kreativmonkey
change nixpkgs url to current nixos release
imported>Hypnosis2839
Enable flakes: prefer declarative config, fix formatting, add note about HM
Line 17: Line 17:
== Enable flakes ==
== Enable flakes ==


Flakes have been introduced with Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html release notes]).
Flakes were introduced with Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html release notes]).
 
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.
 
Note: Flakes is automatically enabled if you installed Nix using the [https://github.com/DeterminateSystems/nix-installer Determinate Installer].


===Temporary===
===Temporary===


Add <code>--experimental-features 'nix-command flakes'</code> when calling the <code>nix</code> command.
Add <code>--experimental-features 'nix-command flakes'</code> when using any <code>nix3</code> commands.


=== Permanent ===
=== Permanent ===


Edit either <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code> and add:
==== NixOS ====
 
Add the following to your system configuration:


<syntaxHighlight lang=text>
<syntaxHighlight lang=nix>
experimental-features = nix-command flakes
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
</syntaxHighlight>
</syntaxHighlight>


Here's a handy copy-paste:
==== Other Distros: With Home-Manager ====
 
If you use HM, add the following to your home-manager config:


<syntaxHighlight lang=text>
<syntaxHighlight lang=nix>
mkdir -p ~/.config/nix
  nix = {
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
    package = pkgs.nix;
    settings.experimental-features = [ "nix-command" "flakes" ];
  };
</syntaxHighlight>
</syntaxHighlight>


If the Nix installation is in multi-user mode, don’t forget to restart the <code>nix-daemon</code>.
===== Other Distros: Without Home-Manager =====


=== NixOS ===
{{ note | Flakes are already enabled if you installed Nix using the [https://github.com/DeterminateSystems/nix-installer Determinate Installer]. }}


On NixOS set the following options in <code>configuration.nix</code> and run <code>nixos-rebuild</code>.
Add the following to <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code>:


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