Noureddine RAMDI / Getting Started with Nix Flakes

Created Sun, 12 Apr 2026 00:00:00 +0000 Modified Sun, 14 Jun 2026 22:08:29 +0000

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?

FeatureChannelsFlakes
ReproducibleNoYes (flake.lock)
ComposableManualNative
EvaluationImpurePure by default
SharingCopy filesURL-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.nix to 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.