nix-platform-specific-options
Installation
SKILL.md
Nix Module Platform-Specific Options
Overview
When writing Nix modules that need to hide platform-specific options (NixOS vs Darwin), using mkIf alone causes infinite recursion. This skill documents the correct pattern.
The Problem
mkIf is evaluated lazily but the option path is still visible during module evaluation. This causes errors like:
error: The option `users.defaultUserShell' does not exist.
Or infinite recursion when config is referenced in option defaults or optionalAttrs conditions.
The Pattern
Use optionalAttrs for platform checks, mkIf for config-dependent checks.