Nix Flakes have become the standard way to manage NixOS configurations. If you’re still using nix-channel, it’s time to make the switch.
What Are Flakes?
Flakes are a way to manage Nix packages and NixOS configurations with a standardized structure. They provide:
- Reproducibility — locked dependencies via
flake.lock - Composability — easily combine multiple flake inputs
- Discoverability — standard schema for outputs
A Minimal flake.nix
{
description = "My NixOS configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager.url = "github:nix-community/home-manager";
};
outputs = { self, nixpkgs, home-manager }: {
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
home-manager.nixosModules.home-manager
];
};
};
}
Key Commands
# Initialize a new flake
nix flake init
# Update all inputs
nix flake update
# Build your NixOS config
sudo nixos-rebuild switch --flake .#myhost
# Enter a dev shell
nix develop
Why Flakes Over Channels?
| Feature | Channels | Flakes |
|---|---|---|
| Reproducible | No | Yes (flake.lock) |
| Composable | Manual | Native |
| Evaluation | Impure | Pure by default |
| Sharing | Copy files | URL-based inputs |
The main advantage is that flake.lock pins exact versions of all inputs, making your system truly reproducible across machines.
Next Steps
- Migrate your
configuration.nixto a flake - Add Home Manager as a flake input
- Structure your config with modules for clean separation
Flakes are the future of Nix. Start small — wrap your existing config in a flake.nix and iterate from there.