Module System
All custom options use the othrys.* namespace (e.g., othrys.desktop.login.enable). Each module follows a consistent pattern.
Standard Module Structure
A module declares options under options.othrys.{category}.{name}, guards config with lib.mkIf cfg.enable, and integrates with Home Manager and impermanence as needed.
Example: Login Manager (greetd)
Options:
options.othrys.desktop.login = {
enable = lib.mkEnableOption "graphical login manager (greetd)";
greeter = lib.mkOption {
type = lib.types.enum ["tuigreet" "cosmic-greeter"];
default = "tuigreet";
description = "Greeter frontend. Both run on greetd.";
};
defaultDesktop = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
Wayland session the default `sessionCommand` launches via `uwsm start`
(e.g. hyprland-uwsm.desktop). The hyprland module sets it. Unused when
`sessionCommand` is set explicitly and ignored by cosmic-greeter, which
lists the installed sessions instead.
'';
};
sessionCommand = lib.mkOption {
type = lib.types.str;
default = defaultSession;
defaultText = lib.literalExpression ''"uwsm start ''${defaultDesktop}" when a compositor sets defaultDesktop, "niri-session" on a niri host, otherwise required'';
description = ''
Command the greeter runs to start the session. The default launches
`defaultDesktop` through uwsm when a compositor registered one, which
hyprland does, and `niri-session` on a niri host. A host running a
desktop othrys does not manage sets it directly.
'';
};
autoLogin = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Skip the greeter and start the session as the primary user (tuigreet
only). Anyone at the console gets the session, so the host must lock
it on idle and before sleep, which `othrys.desktop.idle` provides,
and the module refuses the option without it.
'';
};
};
Config:
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.sessionCommand != "";
message = "othrys.desktop.login has no session to start: enable a compositor module, or set othrys.desktop.login.sessionCommand for a desktop othrys does not manage.";
}
{
assertion = cfg.autoLogin -> config.othrys.desktop.idle.enable;
message = "othrys.desktop.login.autoLogin starts a session for whoever is at the console, so the host needs a lock path: enable othrys.desktop.idle.";
}
{
assertion = cfg.autoLogin -> usersEnabled;
message = "othrys.desktop.login.autoLogin starts the session as the primary user, which needs othrys.system.users.enable.";
}
];
# tuigreet is the minimal greeter that launches the default session. The
# greeter itself runs as the `greeter` account nixpkgs creates, since it
# draws the prompt before anyone has authenticated; only the session
# started after login runs as the primary user. useTextGreeter keeps
# kernel messages off the terminal the TUI draws on.
services.greetd = lib.mkIf (cfg.greeter == "tuigreet") {
enable = true;
useTextGreeter = true;
settings = {
default_session.command = "${pkgs.tuigreet}/bin/tuigreet --time --cmd '${cfg.sessionCommand}'";
initial_session = lib.mkIf (cfg.autoLogin && usersEnabled) {
command = cfg.sessionCommand;
user = username;
};
};
};
# cosmic-greeter is System76's graphical greeter, which configures greetd itself.
services.displayManager.cosmic-greeter.enable = cfg.greeter == "cosmic-greeter";
};
Category Organization
Each modules/{category}/default.nix imports all modules in that category, and nixosModules.default aggregates every category. A consuming flake that imports nixosModules.default pulls in every module, but nothing activates until othrys.{category}.{name}.enable = true is set in the consumer’s configuration.
Five files are left out of their category, since each writes into an option namespace that only an upstream flake’s module declares. modules/system/home.nix, modules/theme/stylix.nixos.nix, modules/system/disko.nix, modules/system/secrets.nixos.nix and modules/system/impermanence.nix are exported as nixosModules.home, nixosModules.stylix, nixosModules.disko, nixosModules.secrets and nixosModules.impermanence, and a host imports each together with the upstream module it configures. nixosModules.full aggregates default, the five and their upstream modules. See Host Configuration.
Shared Options and Platform Files
A module that nix-darwin will implement as well is split into two files.
modules/services/tailscale.nix declares othrys.services.tailscale, and modules/services/tailscale.nixos.nix imports it and
holds every NixOS setting. The category’s default.nix and the individual
export both name the .nixos.nix file, so a NixOS host evaluates exactly what
it did before the split. nix-darwin refuses a write to an option it does not
declare, such as networking.firewall or systemd, so the darwin
implementation of a module, such as git.darwin.nix, imports the shared
file and writes its own settings beside it, and the options keep one name on
both platforms. A shared file also holds what both platforms write the same
way, which is a Home Manager registry entry or an assertion that reads only
othrys options, as git.nix and zsh.nix do, so neither platform file
repeats it.
The split applies to the system modules users, nix, git, locale and
secrets, the editor option and zsh under system/shell, ssh,
tailscale, mosh and yubikey, the development, ollama and t3code apps, the Stylix
adapter, the persistence registry, Floorp, Discord, Vesktop and Ghostty, and the graphical-session
signal in desktop/graphical.nix, which a Mac sets on. Ghostty is split because
its package differs on darwin. apps/gui/chromium.nix stays whole and Linux
only, since nixpkgs builds ungoogled-chromium for Linux alone. The
eval-exports check counts a shared file as exported through its
.nixos.nix file, and fails on a .nixos.nix file with no shared file beside
it.
Home Manager Integration
Home Manager is loaded as a NixOS or nix-darwin module and manages one user, the primary user
named by othrys.system.user.name. A module does not write
home-manager.users itself. It contributes an attribute set to the
othrys.internal.homeConfig registry, under a key that is its own option path.
othrys.internal.homeConfig."apps.gh" = {
programs.gh.enable = true;
};
modules/system/users.nix declares the registry, and modules/system/home.nix
merges every entry into home-manager.users.<name> behind
othrys.system.users.homeManaged.
# The guard is applied here, once, and at the attribute-set level.
# homeManaged implies othrys.system.users.enable, so the user name is
# read only on a host that has the account. A guard on a leaf would
# still declare the Home Manager user and trip the NixOS account
# assertions on a host without one.
home-manager.users = lib.mkIf cfg.homeManaged {
${username} = lib.mkMerge (
# Essential user CLI tools, kept here rather than in
# environment.systemPackages so they follow the user.
[{home.packages = with pkgs; [tree jq just];}]
++ lib.attrValues config.othrys.internal.homeConfig
);
};
The guard sits at the attrset level in that one place, so a headless host never
materializes a Home Manager user. A leaf-level mkIf in each module would
still create the user.
home.nix is exported as nixosModules.home and is not part of
nixosModules.default, so the tree evaluates on a host that imports no Home
Manager module. homeManaged is true when the account exists,
othrys.system.users.homeManager.enable is on and the export is imported. On
any other host users.nix warns once and names every module whose entry was
skipped. A host with the account and homeManager.enable left on fails an
assertion that names the export, since most modules that configure the user
write nothing else.
A module does not read config.home-manager either, for the same reason it
does not write it. A value one Home Manager module needs from another is read
inside the user’s configuration, as modules/apps/gui/vscode/default.nix does
for the neovim that nixvim builds.
A module with a condition of its own wraps the whole entry in a top-level
lib.mkIf, as modules/services/docs.nix does. A false condition drops the
key from the registry.
othrys.internal.homeConfig."services.docs" = lib.mkIf cfg.desktopEntry {
# User-level configuration here
};
Account-level writes, such as group memberships in
users.users.${username}.extraGroups, stay in the module and are guarded on
othrys.system.users.enable at the attrset level. CONTRIBUTING.md carries
the full reasoning, and the contract-guards hook rejects a module that names
home-manager.users or environment.persistence.
Impermanence Pattern
Modules that store persistent state declare their own persistence, in a second
registry, othrys.internal.persist, under the same key as the Home Manager one.
A path in the primary user’s home goes under user, relative to the home.
othrys.internal.persist."apps.{app}" = {
user.directories = [
".config/{app}"
];
};
A system path goes in directories or files.
othrys.internal.persist."services.{service}" = {
directories = [
"/var/lib/{service}"
];
};
Neither form spells a guard. modules/system/impermanence.nix reads the
registry and writes it into environment.persistence under
config.othrys.system.impermanence.persistRoot. It writes the system paths
when impermanence is on, and the paths under user only when
othrys.system.users.enable is on as well, since impermanence reads the
account’s home directory to place the bind mount.
That file is exported as nixosModules.impermanence and is not part of
nixosModules.default, so the tree evaluates on a host that imports no
impermanence module. See Impermanence.