- drop this in
/etc/nixos/flake.nix
{
description = "system flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = {nixpkgs, ...}: {
nixosConfigurations = {
hostname = nixpkgs.lib.nixosSystem {
modules = [
./configuration.nix
];
};
};
};
}
- change
hostname
(and optionally, thenixpkgs
url if e.g. you want to use a stable branch) - run
nix flake update
- rebuild your system (
nixos-rebuild boot
) - congrats you now use flakes
- run
nix flake update
- rebuild your system
You can also freely move the flake (the contents of /etc/nixos
to any other location, and/or create a version-controlled (e.g. git-controlled) repo out of it.
If you do so, you can pass --flake /PATH/TO/FLAKE
to nixos-rebuild
.
Refer to man nixos-rebuild
and man nix3-flake
for more info.
If you do use git, do not ignore the flake.lock; always include it in commits. That's how you keep reproducibility of your config and allow rolling back in case of breakage.