Creating a new module
1. Create the module file
Create a new file in the appropriate directory:modules/nixos/— System-level configurationmodules/home/— User-level configurationmodules/generic/— Shared between both
2. Write the module
Follow the standard module structure:3. Register the import
Add the file to the correspondingdefault.nix:
4. Define options
Add any new options tomodules/nixos/options.nix under the marchyo.* namespace:
5. Add a test
Add an evaluation test intests/module-tests.nix:
Home Manager modules
Home Manager modules that need NixOS config useosConfig:
Best practices
- Use
lib.mkIffor feature-gated configuration blocks - Use
lib.mkDefaultfor values consumers should be able to override - Use
lib.mkMergewhen a module has multiple conditional branches - Define all options in
options.nix— never definemarchyo.*options in individual modules - Add a test for every new feature flag