nix-option-types

Defines Nix module options using mkOption, type combinators, and submodule patterns.

1|Updated Aug 21, 2023
One-click install
npx skills add https://github.com/jmuchovej/homelab --skill nix-option-types-jmuchovej
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nix-option-types
Source: https://github.com/jmuchovej/homelab/tree/main/src/modules/ai-tools/skills/nix-option-types
Command: npx skills add https://github.com/jmuchovej/homelab --skill nix-option-types-jmuchovej

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Nix modules requires choosing the correct option types and declaration helpers, and picking the wrong type or forgetting a default leads to confusing evaluation errors. This Skill provides ready-to-use patterns for declaring options correctly the first time. ## Core Features & Use Cases - Helper Selection Guidance: Shows when to use mkEnableOption, mkPackageOption, or mkOption for common declaration scenarios. - Type Reference Patterns: Covers basic types (str, int, port, path, package), collection types (listOf, attrsOf, enum, nullOr, either), and validated port ranges. - Submodule Pattern: Demonstrates attrsOf submodule declarations for nested service configuration with per-instance options. - Use Case: When adding a new service to a NixOS or Home Manager module, use these patterns to declare an enable flag, a validated port option, and a package option with sensible defaults. ## Quick Start Ask the AI to define Nix module options for a new service including an enable flag, a port, and a package using mkOption and the appropriate types.

Frequently Asked Questions about nix-option-types

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

FAQPage Schema
How do I define options in a Nix module with mkOption?

Use mkOption with a type, default, and description to declare module options. For boolean enable flags, prefer mkEnableOption, and for package options use lib.mkPackageOption, which handles defaults automatically.

What Nix option type should I use for a list or attribute set?

Use types.listOf for lists and types.attrsOf for attribute sets, wrapping the element type such as types.listOf types.str. For a fixed set of allowed values, use types.enum with a list of permitted strings.

When should I use mkEnableOption vs mkOption in Nix?

Use mkEnableOption for boolean enable flags since it generates a standard description and defaults to false. Use mkOption for everything else, including strings, integers, ports, paths, and composite types.

How do I create nested submodule options in Nix?

Wrap types.submodule inside types.attrsOf to declare named instances of a nested option set. Each submodule defines its own options block, letting users configure entries like services.myService with enable and port fields.

Does Nix validate port numbers in module options?

Yes, types.port validates that values fall within the 1-65535 range at evaluation time. Declaring an option with types.port catches invalid port assignments before the configuration is built.