Contributing
cattery-modules lives at
github.com/nixcafe/cattery-modules. It is a
purr flake (namespace = "cattery", bundleModules = true), so a new
modules/<platform>/<category>/<name>/default.nix is picked up without being registered
anywhere.
Repository layout
flake.nix inputs, extraModules, and the purr mkFlake call
modules/
nixos/ NixOS modules
darwin/ nix-darwin modules
shared/ modules imported by NixOS and nix-darwin
home/ Home Manager modules
lib/
module/ mkDefaultEnabled
secrets/ agenix option builders
utils/ getRootDomain, escapeSystemdPath
checks/
git-hooks/ nixfmt, deadnix, statix
unit-tests/ runs tests/unit
module-eval/ runs tests/integration
shells/default/ dev shell with cattery-test and cattery-check-config
tests/ runner, helpers, unit and integration suitesModule style
Modules follow the nixpkgs style. Each one declares options.${namespace}.<path> and a
config guarded by lib.mkIf cfg.enable. There are no module generators or wrapper
builders, so write both blocks out:
# modules/home/cli-apps/tool/example/default.nix
{
config,
lib,
namespace,
pkgs,
...
}:
let
cfg = config.${namespace}.cli-apps.tool.example;
in
{
options.${namespace}.cli-apps.tool.example = {
enable = lib.mkEnableOption "the example tool";
persistence = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to persist the state of this module with impermanence.";
};
extraOptions = lib.mkOption {
type = lib.types.attrs;
default = { };
description = "Additional options merged into `programs.example`.";
};
};
config = lib.mkIf cfg.enable {
programs.example = lib.mkMerge [
{ enable = true; }
cfg.extraOptions
];
${namespace}.system.impermanence = lib.mkIf cfg.persistence {
xdg.data.directories = [ "example" ];
};
};
}- Enable options use
lib.mkEnableOption "<noun phrase>". It adds "Whether to enable" and the final period itself, so pass a bare phrase such as"the GnuPG agent". - Any other boolean, including an enable option that defaults to
true, useslib.mkOptionwithtype = lib.types.booland a description that starts with "Whether to". Do not extendmkEnableOptionwith// { ... }. extraOptionsis merged withlib.mkMerge [ { ... } cfg.extraOptions ], never with//. Uselib.recursiveUpdateonly for plain data, such as the input ofpkgs.formats.persistencedefaults totrueand adds paths throughcattery.system.impermanence.- Rooms turn modules on with
lib.${namespace}.module.mkDefaultEnabledorlib.mkDefault. In Home Manager rooms, mark platform-specific members with a# Linux onlyor# Darwin onlycomment. - Home Manager modules for one platform guard their
configwithpkgs.stdenv.hostPlatform.isLinuxorisDarwin. Do not use the shortpkgs.stdenv.isLinux, which prints deprecation warnings.
Option descriptions
Every public option needs a description. tests/integration/test-options.nix walks the
evaluated NixOS, nix-darwin, and Home Manager options, including submodule options, and
fails on any public option without one.
- Write short factual phrases that end with a period.
- Refer to options with
{option}`...`, files with{file}`...`, commands with{command}`...`, and man pages with{manpage}`...`. - Keep descriptions and comments in plain ASCII prose without semicolons, em or en dashes, or curly quotes, and do not mention counts that go stale.
- When a test asserts a description, update the expected string in the same change.
The system argument
cattery uses two tiers:
| Where | How to get the system |
|---|---|
checks/, shells/ | Take system as a function argument. purr passes it, for example inputs.git-hooks.lib.${system} |
modules/ | Never take system. Read pkgs.stdenv.hostPlatform.system, for example inputs.agenix.packages.${pkgs.stdenv.hostPlatform.system}.default |
nix-darwin options
nix-darwin cannot run on Linux, so check every nix-darwin option name and type against
the locked darwin input in the Nix store, and assert the evaluated values in
tests/integration/test-darwin.nix. The integration suites evaluate aarch64-darwin
configurations from Linux.
Development shell
nix developThe shell installs the pre-commit hooks and provides nixfmt, deadnix, statix, jq,
and two helpers:
| Command | Purpose |
|---|---|
cattery-test [pattern] | Runs tests/run-tests.sh from anywhere in the checkout. Prints one PASS or FAIL line per test. The pattern is a grep -E over file :: group :: test |
cattery-check-config <flake-dir> | Prints the drvPath of every system, home, and image of a flake that uses cattery, as sorted JSON |
cattery-check-config evaluates the consumer flake with
--override-input cattery-modules path:<checkout> and --no-write-lock-file, so the
consumer's flake.lock stays untouched. Run it before and after a change to see which
hosts and homes it affects:
cattery-check-config ~/nix-config > before.json
# make the change
cattery-check-config ~/nix-config --diff before.json > after.jsonTests and checks
nix flake check # git-hooks, unit-tests, and module-eval
./tests/run-tests.sh 'darwin' # live per-test output with a filter
nix fmt # nixfmt-tree over the repository| Check | Contents |
|---|---|
checks.<system>.git-hooks | nixfmt, deadnix, and statix |
checks.<system>.unit-tests | tests/unit/test-*.nix, the lib.cattery helpers |
checks.<system>.module-eval | tests/integration/test-*.nix, real NixOS, nix-darwin, and Home Manager evaluations of the exported default bundles, with and without purr |
New test-*.nix files are found automatically. Put fixtures under tests/fixtures.
Linting
statix.toml sets disabled = [], so every lint is on, including repeated_keys. Group
sibling attributes instead of repeating a prefix:
xdg = {
cache.directories = [ "example" ];
data.directories = [ "example" ];
};deadnix -L skips unused lambda arguments that the pre-commit hook still rejects, so run
plain deadnix --fail . as well.
Pull requests
- Branch from
mainwith afeat/,fix/,chore/, ordocs/prefix. - Write code, comments, and commit messages in English.
- Run
nix fmtandnix flake check. Test configuration changes on a real machine withnixos-rebuild test,home-manager switch, ordarwin-rebuild switch. - Open a pull request against
main. CI runsnix flake check, and every push tomainpublishes a rolling release to FlakeHub.
Documentation changes for this site go to
nixcafe/nixcafe-docs under
apps/cattery-modules.