nix-module-template

Generates standard Nix module structures for NixOS, Home Manager, and nix-darwin configurations.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Nix modules from scratch requires remembering the correct options/config structure, the mkIf enable pattern, and platform-specific conventions for NixOS, Home Manager, and nix-darwin, which leads to inconsistent or broken modules. ## Core Features & Use Cases - Standard Module Skeleton: Provides the canonical options/config pattern using mkEnableOption, mkIf, and the cfg convention. - Platform-Specific Templates: Includes ready-to-adapt examples for NixOS services with systemd units, Home Manager programs with packages and xdg config files, and nix-darwin system defaults. - Use Case: When adding a new service to your NixOS configuration, start from the template to declare options like enable and port, then wire up the systemd service under mkIf cfg.enable without structural mistakes. ## Quick Start Create a new NixOS module for my-service with an enable option and a port option using the standard module template.

Frequently Asked Questions about nix-module-template

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

FAQPage Schema
How do I create a NixOS module from scratch?

Define an options block with mkEnableOption and any typed mkOption entries, then wrap your configuration in mkIf cfg.enable. Access values through a let-bound cfg variable pointing at your option path.

How to write a Home Manager module in Nix?

Declare options under programs.yourApp with mkEnableOption, then in the config block guarded by mkIf cfg.enable add home.packages entries and xdg.configFile definitions for the application's configuration files.

What is the mkIf cfg.enable pattern in Nix modules?

It is the standard convention where all configuration effects are wrapped in mkIf cfg.enable so the module only applies changes when the user sets the enable option to true. This keeps modules opt-in and composable.

Can the same Nix module work on NixOS and nix-darwin?

Not directly, because option namespaces differ between platforms. NixOS uses services and systemd options while nix-darwin uses system.defaults and its own option tree, so each platform needs its own module file.

Why does my Nix module apply config even when disabled?

This happens when configuration attributes are placed outside the mkIf cfg.enable guard. Move all side-effecting config inside the conditional block so nothing is applied unless the enable option is true.