nixos-module-builder

Create modular NixOS and Home Manager modules with enable options.

1|Updated Mar 20, 2026
One-click install
npx skills add https://github.com/Thomashighbaugh/opencode --skill nixos-module-builder
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nixos-module-builder
Source: https://github.com/Thomashighbaugh/opencode/tree/main/skills/nixos-module-builder
Command: npx skills add https://github.com/Thomashighbaugh/opencode --skill nixos-module-builder

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This guide eliminates guesswork and inconsistency when adding new NixOS or Home Manager modules by prescribing a repeatable "activate-by-enabling-option" module pattern so features remain opt-in, composable, and easy to maintain.

Core Features & Use Cases

  • Opinionated Module Pattern: Shows how to declare options.modules.<category>.<name> with mkEnableOption and additional mkOption entries to expose sub-options and package variants.
  • Conditional Configuration: Demonstrates using mkIf, mkMerge, optionals, and optionalAttrs to compose configuration safely based on enable flags and sub-options.
  • Integration Workflow: Explains where to place modules in modules/nixos or modules/home-manager, how to add them to a category's default.nix import list, and how to enable them in hosts/<hostname>/default.nix or home/<username>/default.nix.
  • Validation and Examples: Provides references for hardware, desktop, services, and virtualization patterns, plus commands to validate changes with nixos-rebuild and nix flake check.

Quick Start

Create a new module file in the appropriate modules/<category>/ directory that defines options.modules.<category>.<name>.enable with mkEnableOption, implements config guarded by mkIf cfg.enable, adds the file to the category default.nix imports, and enable it in the host or user modules to test with nixos-rebuild.

Frequently Asked Questions about nixos-module-builder

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

FAQPage Schema
How do I create reusable NixOS modules with enable options?

To create reusable NixOS modules, define options.modules.<category>.<name>.enable with mkEnableOption, implement config guarded by mkIf cfg.enable, and add the file to the category default.nix imports to produce opt-in composable configurations.

What's the best way to structure Home Manager modules in a flake?

The best way to structure Home Manager modules in a flake is placing them in modules/home-manager, adding imports to default.nix, and enabling them in home/<username>/default.nix for consistent user-level configuration management.

How does mkIf work with mkMerge for conditional NixOS configuration?

mkIf guards configuration blocks based on enable flags while mkMerge safely composes multiple conditional blocks together, allowing NixOS modules to apply settings only when specific options are activated without conflicts.

Can I use mkOption to expose package variants in NixOS modules?

Yes, you can use mkOption alongside mkEnableOption to expose sub-options and package variants within NixOS modules, allowing users to select different package versions or configurations when enabling the module.

How do I validate NixOS module changes before rebuilding?

Validate NixOS module changes by running nixos-rebuild to test the configuration or nix flake check to verify the flake structure and module definitions without applying system modifications.

When should I not use the enable option pattern for NixOS modules?

The enable option pattern should not be used when a module must always apply configuration unconditionally, as mkEnableOption is designed specifically for opt-in features that remain composable across host and user modules.