Skip to content
LogoLogo

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 suites

Module 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, uses lib.mkOption with type = lib.types.bool and a description that starts with "Whether to". Do not extend mkEnableOption with // { ... }.
  • extraOptions is merged with lib.mkMerge [ { ... } cfg.extraOptions ], never with //. Use lib.recursiveUpdate only for plain data, such as the input of pkgs.formats.
  • persistence defaults to true and adds paths through cattery.system.impermanence.
  • Rooms turn modules on with lib.${namespace}.module.mkDefaultEnabled or lib.mkDefault. In Home Manager rooms, mark platform-specific members with a # Linux only or # Darwin only comment.
  • Home Manager modules for one platform guard their config with pkgs.stdenv.hostPlatform.isLinux or isDarwin. Do not use the short pkgs.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:

WhereHow 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 develop

The shell installs the pre-commit hooks and provides nixfmt, deadnix, statix, jq, and two helpers:

CommandPurpose
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.json

Tests 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
CheckContents
checks.<system>.git-hooksnixfmt, deadnix, and statix
checks.<system>.unit-teststests/unit/test-*.nix, the lib.cattery helpers
checks.<system>.module-evaltests/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

  1. Branch from main with a feat/, fix/, chore/, or docs/ prefix.
  2. Write code, comments, and commit messages in English.
  3. Run nix fmt and nix flake check. Test configuration changes on a real machine with nixos-rebuild test, home-manager switch, or darwin-rebuild switch.
  4. Open a pull request against main. CI runs nix flake check, and every push to main publishes a rolling release to FlakeHub.

Documentation changes for this site go to nixcafe/nixcafe-docs under apps/cattery-modules.