Flakes: The Future of Nix
What Are Flakes?
Basic Flake Structure
{
description = "My project flake";
inputs = {
# Core dependencies
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
# Additional dependencies
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in {
# Development environment
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
nodejs_20
yarn
];
};
# Packages
packages = {
default = self.packages.${system}.myapp;
myapp = pkgs.stdenv.mkDerivation {
name = "myapp";
version = "1.0.0";
src = ./src;
buildPhase = ''
# Build commands
'';
installPhase = ''
mkdir -p $out/bin
cp myapp $out/bin/
'';
};
};
# Apps (runnable packages)
apps.default = {
type = "app";
program = "${self.packages.${system}.myapp}/bin/myapp";
};
}
);
}Flake Inputs and Outputs
Inputs
Outputs
Using Flakes in DevOps Workflows
Development Environment Flake
CI/CD Pipeline Flake
Microservices Flake
NixOS System Configuration with Flakes
Advanced Flake Techniques
Multi-Environment Deployments
Composing Flakes with Registry Overrides
Managing Flake Dependencies
Dependency Locking and Updates
Dependency Visualization
Flakes in CI/CD Pipelines
Real-World DevOps Projects with Flakes
NixOS Server Fleet Management
Best Practices for Flakes in Production
Flakes Command Reference
Conclusion
Further Resources
Last updated