WR

writing-nix

Provides guidelines and anti-pattern warnings for writing clean, declarative, and efficient Nix code.

Install

mkdir -p .claude/skills/writing-nix-askuswt && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/11608" && unzip -o skill.zip -d .claude/skills/writing-nix-askuswt && rm skill.zip

Installs to .claude/skills/writing-nix-askuswt

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Write idiomatic, maintainable, and performant Nix code. Use when creating or refactoring Nix expressions, modules, overlays, packages, flake outputs, and helper functions, including anti-pattern avoidance and evaluation/build performance practices.
248 chars✓ has a “when” trigger
Advanced

Key capabilities

  • Write declarative Nix code
  • Avoid the 'with' statement
  • Minimize recursive attributes ('rec')
  • Design clear Nix module structures
  • Use strict option types in modules
  • Optimize Nix evaluation and build performance

How it works

The skill provides guidance on writing Nix code by adhering to core principles like declarativeness and explicitness, avoiding critical anti-patterns, and following best practices for module design and performance.

Inputs & outputs

You give it
Nix expressions, modules, overlays, packages, flake outputs, or helper functions
You get back
idiomatic, maintainable, and performant Nix code

When to use writing-nix

  • Refactor Nix expression
  • Optimize module configuration
  • Check for Nix anti-patterns

About this skill

Writing Nix

Core Principles

  1. Declarative over Imperative: Describe what, not how.
  2. Explicit over Implicit: Avoid magic scoping or hidden dependencies.
  3. Hermetic: No side effects, no network access during build (except fixed-output derivations).

Critical Anti-Patterns

1. The with Statement

NEVER use with. It breaks static analysis, tools (LSP), and readability.

# BAD
meta = with lib; { license = licenses.mit; };

# GOOD
meta = { license = lib.licenses.mit; };

2. Recursive Attributes (rec)

Avoid rec when let-in suffices. rec can cause infinite recursion and expensive evaluation.

# BAD
rec {
  version = "1.0";
  name = "pkg-${version}";
}

# GOOD
let
  version = "1.0";
in {
  inherit version;
  name = "pkg-${version}";
}

3. Over-wide option surfaces

Do not expose options for hypothetical use cases. Keep interfaces minimal and intentional.

Module Design

Use clear module structure:

{ config, lib, pkgs, ... }:
let
  inherit (lib) mkEnableOption mkIf mkOption types;
  cfg = config.some.path;
in {
  options.some.path = {
    enable = mkEnableOption "description";
  };

  config = mkIf cfg.enable {
    # implementation
  };
}

Guidelines:

  • Define strict option types.
  • Use mkDefault for overridable defaults.
  • Prefer mkMerge + mkIf for conditional composition.
  • Prefer inherit (...) when names match.

Expression Style

  • Prefer attrset lookup over long if/else chains for multi-branch selection.
  • Keep temporary variables close to usage.
  • Keep functions small and names descriptive.

Performance Practices

Evaluation:

  • Avoid forcing large attrsets when not needed.
  • Avoid expensive repeated imports and computations.
  • Keep hot-path expressions straightforward.

Build:

  • Minimize runtime closures.
  • Keep sources clean (cleanSource/filters) to avoid rebuild churn.

Function Patterns

  • Destructure arguments in function headers.
  • Use override for function arguments and overrideAttrs for derivation attrs.

Validation

After edits, run the most relevant checks available in the target repo (eval/build/test).

Output Contract

Report:

CHANGES MADE:
- <file>: <what changed and why>

THINGS I DIDN'T TOUCH:
- <file>: <why intentionally unchanged>

POTENTIAL CONCERNS:
- <risk or follow-up checks>

When not to use it

  • When using the 'with' statement, as it breaks static analysis and readability.
  • When exposing options for hypothetical use cases, leading to over-wide option surfaces.
  • When using 'rec' unnecessarily, as it can cause infinite recursion.

Limitations

  • NEVER use `with`.
  • Avoid `rec` when `let-in` suffices.
  • Do not expose options for hypothetical use cases.

How it compares

This skill offers specific, opinionated guidance on Nix coding style and anti-pattern avoidance, directly addressing common pitfalls to produce more maintainable and performant Nix code than an unguided approach.

Compared to similar skills

writing-nix side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
writing-nix (this skill)04moNo flagsAdvanced
software-architecture3336moNo flagsIntermediate
effective-go3239moNo flagsBeginner
solid-principles579moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

You might also like

software-architecture

davila7

Guide for quality focused software architecture. This skill should be used when users want to write code, design architecture, analyze code, in any case that relates to software development.

333868

effective-go

openshift

Apply Go best practices, idioms, and conventions from golang.org/doc/effective_go. Use when writing, reviewing, or refactoring Go code to ensure idiomatic, clean, and efficient implementations.

323536

solid-principles

SmidigStorm

Enforce SOLID principles (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion) in object-oriented design. Use when writing or reviewing classes and modules.

57236

typescript-review

metabase

Review TypeScript and JavaScript code changes for compliance with Metabase coding standards, style violations, and code quality issues. Use when reviewing pull requests or diffs containing TypeScript/JavaScript code.

39178

cloudflare-manager

qdhenry

Comprehensive Cloudflare account management for deploying Workers, KV Storage, R2, Pages, DNS, and Routes. Use when deploying cloudflare services, managing worker containers, configuring KV/R2 storage, or setting up DNS/routing. Requires CLOUDFLARE_API_KEY in .env and Bun runtime with dependencies installed.

25135

react-modernization

wshobson

Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.

21134

Search skills

Search the agent skills registry