Agent skill
nix-flakes
Creates reproducible builds, manages flake inputs, defines devShells, and builds packages with flake.nix. Use when initializing Nix projects, locking dependencies, or running nix build/develop commands.
Install this agent skill to your Project
npx add-skill https://github.com/knoopx/pi/tree/main/agent/skills/nix-flakes
SKILL.md
Nix Flakes
Modern Nix project management with hermeticity and reproducibility through flake.lock.
Core Commands
Project Management
# Initialize a new flake in the current directory
nix flake init
# Create a new flake from template
nix flake new hello -t templates#hello
# Update flake.lock (updates all inputs)
nix flake update
# Update specific input only
nix flake update nixpkgs
# Lock without updating (create missing entries)
nix flake lock
# Check flake for syntax and common errors
nix flake check
# Show flake outputs
nix flake show
# Show flake metadata (inputs, revisions)
nix flake metadata path:.
nix flake info path:. # Alias for metadata
# Prefetch flake and inputs into store
nix flake prefetch github:NixOS/nixpkgs
nix flake prefetch-inputs path:.
# Clone flake repository
nix flake clone nixpkgs --dest ./nixpkgs
Running and Building
Always prefix local flake paths with path: (e.g., path:.) to ensure Nix uses all files in the directory without requiring them to be staged in Git.
# Build the default package
nix build path:.
# Build a specific output
nix build path:.#packageName
# Run the default app
nix run path:.
# Run a specific app from a flake
nix run path:.#appName
# Run an app from a remote flake
nix run github:numtide/treefmt
Development Environments
In a headless environment, use nix develop with --command to run tasks within the environment.
# Run a command inside the devShell
nix develop path:. --command make build
# Check if current environment matches devShell
nix develop path:. --command env
Flake Structure (flake.nix)
A basic flake.nix pattern:
{
description = "A basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
packages.${system}.default = pkgs.hello;
devShells.${system}.default = pkgs.mkShell {
buildInputs = [ pkgs.git pkgs.vim ];
};
};
}
Best Practices
- Locking: Manage the
flake.lockfile to ensure reproducibility. - Purity: Flakes are "pure" by default. They cannot access files outside the flake directory unless they are tracked (e.g. in the git tree if using git).
- Non-Interactive: When using
nix develop, always use the--commandflag to ensure scripts remain non-interactive.
Debugging Flakes
# Inspect inputs
nix flake metadata path:.
# Evaluate a specific output
nix eval path:.#packages.x86_64-linux.default.name
Related Skills
- nix: Run applications without installation and create development environments using Nix.
- nh: Manage NixOS and Home Manager operations with improved output using nh.
Related Tools
- search-nix-packages: Search for packages available in the NixOS package repository when working with flakes.
- search-nix-options: Find configuration options available in NixOS for flake configurations.
- search-home-manager-options: Find configuration options for Home Manager in flake setups.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
conventional-commits
Writes and reviews Conventional Commits commit messages (v1.0.0) to support semantic versioning and automated changelogs. Use when drafting git commit messages, PR titles, release notes, or when enforcing a conventional commit format (type(scope): subject, BREAKING CHANGE, footers, revert).
skill-authoring
Writes effective pi skills with proper structure, concise content, and progressive disclosure. Use when creating new skills, improving existing skills, or reviewing skill quality.
gtkx
Build GTK4 desktop applications with GTKX React framework. Use when creating React components that render as native GTK widgets, working with GTK4/Libadwaita UI, handling signals, virtual lists, menus, or building Linux desktop UIs.
nu-shell
Processes structured data through pipelines, filters tables, transforms JSON/CSV/YAML, and defines custom commands. Use when scripting with typed parameters or working with tabular data.
nix
Runs packages temporarily, creates isolated shell environments, and evaluates Nix expressions. Use when executing tools without installing, debugging derivations, or working with nixpkgs.
jj-hunk
Programmatic hunk selection for jj (Jujutsu). Use when splitting commits, making partial commits, or selectively squashing changes without interactive UI.
Didn't find tool you were looking for?