writing-nix

Enforce idiomatic Nix module patterns with typed options and namespaced configuration.

340|18|Updated May 11, 2023
One-click install
npx skills add https://github.com/khaneliman/khanelinix --skill writing-nix
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: writing-nix
Source: https://github.com/khaneliman/khanelinix/tree/main/modules/common/ai-tools/skills/writing-nix
Command: npx skills add https://github.com/khaneliman/khanelinix --skill writing-nix

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill helps you write idiomatic, maintainable Nix code by avoiding anti-patterns and by applying a clean module system design.

Core Features & Use Cases

  • Standard Module Pattern: Defines a reusable skeleton for Nix modules that exposes a clear configuration interface.
  • Safe Design & Typing: Enforces proper option namespaces, strict types, and sane defaults to improve reliability.
  • Performance-conscious: Encourages lazy evaluation, minimal imports, and clean separation of concerns to reduce build impact.
  • Use Case: When building a NixOS module collection, apply the pattern to create new modules quickly with consistency and safety.

Quick Start

Create a new Nix module following the standard skeleton under modules/your-module and enable it in your configuration.

Frequently Asked Questions about writing-nix

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write idiomatic Nix modules with best practices?

Idiomatic Nix modules require a standard pattern using { config, lib, pkgs, ... } signatures, namespaced options, and strict type definitions with sensible defaults to ensure maintainability and prevent anti-patterns.

What is the standard pattern for NixOS module design?

The standard NixOS module design pattern enforces clear configuration interfaces by namespacing options, applying strict types, setting sane defaults, and maintaining clean separation of concerns to improve module reliability.

How do I avoid common anti-patterns when writing Nix code?

Avoid Nix anti-patterns by enforcing lazy evaluation, minimizing imports, and using strict type definitions with sensible defaults, which collectively reduce build impact and improve code maintainability.

Does writing Nix modules with strict types improve performance?

Strict typing in Nix modules improves reliability, while performance gains come from following performance-conscious patterns like lazy evaluation, minimal imports, and clean separation of concerns to reduce build impact.

Can I use this Nix module pattern for personal projects and teams?

Yes, the standard Nix module pattern suits both personal projects and teams by providing a reusable skeleton that enforces consistency, safe design, and maintainable code across a NixOS module collection.

Why do my Nix modules need namespaced options under a specific prefix?

Namespaced options under a specific prefix prevent naming collisions and maintain a clear configuration interface, which is a core requirement for safe design and strict typing in idiomatic Nix modules.