Flakes: Difference between revisions
imported>Mic92 Initial documentation for nix flakes |
imported>Mic92 add nixos example |
||
| Line 8: | Line 8: | ||
This lock file describes provides hashes for sources and locks the revision | This lock file describes provides hashes for sources and locks the revision | ||
of external version control system. | of external version control system. | ||
Nix flakes intents to replace nix channels and the nix search path (NIX_PATH). | Nix flakes intents to replace nix channels and the nix search path (<code>NIX_PATH</code>). | ||
== Installing nix flakes == | == Installing nix flakes == | ||
| Line 26: | Line 26: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
On non-nixos system install `nixUnstable` in your environment and add these lines to your | On non-nixos system install `nixUnstable` in your environment and add these lines to your <code>/etc/nix/nix.conf</code>: | ||
<syntaxHighlight> | |||
experimental-features = nix-command flakes | experimental-features = nix-command flakes | ||
</syntaxHighlight> | |||
There is no official installer yet, but it is possible to download the latest snapshot nix from hydra | |||
as shown in this [https://github.com/Mic92/dotfiles/blob/27a5b81964ecb8722796018a8c4ed7b149f05b96/.github/workflows/build.yml#L33 github action]. | |||
== Using nix flakes with NixOS == | |||
nixos-rebuild switch will reads its configuration from <code>/etc/nixos/flake.nix</code> if is present. | |||
A basic nixos flake.nix could look like this: | |||
<syntaxHighlight lang=nix> | |||
{ | |||
description = "NixOS configuration with flakes"; | |||
outputs = { self, nixpkgs }: { | |||
# replace 'joes-desktop' with your hostname here. | |||
nixosConfigurations.joes-desktop = nixpkgs.lib.nixosSystem { | |||
system = "x86_64-linux"; | |||
modules = [ ./configuration.nix ]; | |||
} | |||
}; | |||
} | |||
</syntaxHighlight> | |||
nixos-rebuild also allows to specify different flake using the <code>--flake</code> flag: | |||
<syntaxHighlight lang=console> | |||
$ sudo nixos-rebuild switch --flake '.#' | |||
</syntaxHighlight> | |||
By default nixos-rebuild will use the currents system hostname to lookup the right nixos configuration in <code>nixosConfigurations</code>. You can also override this by using appending it to the flake parameter: | |||
<syntaxHighlight lang=console> | |||
$ sudo nixos-rebuild switch --flake '/etc/nixos#joes-desktop' | |||
</syntaxHighlight> | |||