Files
Nomarchy/core/system/options.nix
Bernardo Magri 7fa909ddf4 fix: centralize state defaults via lib/state-schema.nix
Kills a recurring bug class: state defaults previously lived in three
parallel places that drifted apart over time.

  - lib/state-schema.nix          (the canonical schema, referenced
                                   nowhere except a description string)
  - core/system/options.nix       (default = "..." clauses on options)
  - core/home/options.nix         (same, on home options)
  - core/home/state.nix           (`or "..."` fallbacks for state.json reads)

When `state.json` is missing a key, three files have to agree on the
fallback. They keep silently drifting:

  - The OOTB QA audit shipped fixes for this pattern.
  - Earlier this session, `chore: switch default theme summer-night → nord`
    fixed core/system/options.nix and core/home/state.nix — but missed
    core/home/options.nix, which still defaulted nomarchy.theme to
    "summer-night". Every consumer of the home option
    (features/default.nix, vscode.nix, waybar, hyprland, theme engine)
    resolved to the wrong theme when state.json was blank.

This change:

  - Imports lib/state-schema.nix into all three consumers and replaces
    every hardcoded default with `schema.<scope>.<key>`.
  - Fixes the lingering nomarchy.theme = "summer-night" home-side bug as
    a side-effect.
  - Touches roughly 25 literals across the three files.

Verified `nix flake check --no-build` passes and every centralized value
evaluates to the exact literal it previously had. Off-schema option-only
defaults (isLightMode, formFactor, cursor.*, iconsTheme, keyring.enable,
etc.) are left hardcoded — they have no state.json counterpart, so
there's no source-of-truth split to resolve.

Out of scope (follow-up):
  - Have installer/install.sh generate /mnt/etc/nixos/state.json from
    the schema instead of hardcoded JSON — would close the last
    split-brain surface (the installer can still drift from schema).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-18 17:52:47 +01:00

217 lines
7.6 KiB
Nix

{ config, lib, pkgs, ... }:
let
# Defaults live in lib/state-schema.nix so they can't drift between this
# file, core/home/options.nix, and core/home/state.nix's `or` fallbacks.
schema = import ../../lib/state-schema.nix { inherit lib; };
in
{
options.nomarchy.system = {
dns = lib.mkOption {
type = lib.types.enum [ "Cloudflare" "Google" "DHCP" "Custom" ];
default = schema.system.dns;
description = "Selected DNS provider.";
};
customDns = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = schema.system.customDns;
description = "List of custom DNS servers.";
};
wifi = {
powersave = lib.mkOption {
type = lib.types.bool;
default = schema.system.wifi.powersave;
description = "Whether to enable wifi power saving.";
};
};
timezone = lib.mkOption {
type = lib.types.str;
default = schema.system.timezone;
description = "System timezone.";
};
formFactor = lib.mkOption {
type = lib.types.enum [ "laptop" "desktop" ];
default = "laptop";
description = ''
Physical form factor. Drives UI affordances (battery widget,
future lid handling / TLP). Default "laptop" battery widget
is harmless on a desktop (renders empty when no BAT* is
present), so the safe default is "show, don't hide". The
installer auto-detects via /sys/class/power_supply/BAT* and
writes the explicit value into the generated system.nix.
'';
};
features = {
fingerprint = lib.mkOption {
type = lib.types.bool;
default = schema.system.features.fingerprint;
description = "Whether to enable fingerprint support.";
};
fido2 = lib.mkOption {
type = lib.types.bool;
default = schema.system.features.fido2;
description = "Whether to enable FIDO2 support.";
};
hybridGPU = lib.mkOption {
type = lib.types.bool;
default = schema.system.features.hybridGPU;
description = "Whether to enable hybrid GPU support (supergfxd).";
};
};
theme = lib.mkOption {
type = lib.types.str;
default = schema.system.theme;
description = "Selected system theme.";
};
# ----- Tier 1 system features (all opt-in, no behavioural change off) ---
snapper = {
enable = lib.mkEnableOption ''
Snapper-driven BTRFS timeline snapshots of `/`. Auto-disables when
`/` isn't BTRFS. Includes a `nixos-rebuild-snap` wrapper that takes
a "Pre-rebuild" snapshot before each switch.
'';
};
hibernation = {
enable = lib.mkEnableOption ''
suspend-then-hibernate (lid close, idle, power button). NOTE: this
requires a disk swap device or swapfile sized to at least RAM
zRAM alone is not enough.
'';
idleMinutes = lib.mkOption {
type = lib.types.int;
default = 30;
description = "Idle minutes before suspend-then-hibernate fires.";
};
};
laptop = {
enable = lib.mkOption {
type = lib.types.bool;
default = config.nomarchy.system.formFactor == "laptop";
defaultText = lib.literalExpression ''config.nomarchy.system.formFactor == "laptop"'';
description = ''
Laptop power preset: TLP (with sane AC/battery governors),
`services.upower`, `services.thermald` (x86_64), a brightnessctl
udev rule, and a logind lid-switch policy. Force-disables
`services.power-profiles-daemon` (mutually exclusive with TLP).
Lid-close defers to `nomarchy.system.hibernation.enable`:
suspend-then-hibernate when on, suspend otherwise. Defaults on
when `formFactor = "laptop"`.
'';
};
thermald = lib.mkOption {
type = lib.types.bool;
default = pkgs.stdenv.hostPlatform.isx86_64;
defaultText = lib.literalExpression "pkgs.stdenv.hostPlatform.isx86_64";
description = ''
Enable `services.thermald` (Intel thermal daemon). Default true on
x86_64. Harmless no-op on AMD; gated off on aarch64.
'';
};
};
desktop = {
enable = lib.mkOption {
type = lib.types.bool;
default = config.nomarchy.system.formFactor == "desktop";
defaultText = lib.literalExpression ''config.nomarchy.system.formFactor == "desktop"'';
description = ''
Desktop preset: pins `powerManagement.cpuFreqGovernor` to
`"performance"` and enables `services.zfs.autoScrub` and
`services.zfs.trim` so a future ZFS pool gets sensible
maintenance without further config. The ZFS knobs are no-ops
until the user adds `boot.supportedFilesystems = [ "zfs" ]`
and a pool. Defaults on when `formFactor = "desktop"`. Battery
widget filtering is already handled by `formFactor` itself in
`features/desktop/waybar/default.nix`.
'';
};
};
accessibility = {
enable = lib.mkEnableOption ''
Accessibility preset: AT-SPI2 framework, the Orca screen reader
on PATH, and a larger default cursor size. Off by default
accessibility is a personal preference, not a hardware-derived
signal. The Hyprland-side keybinding to launch Orca is a
separate roadmap item.
'';
cursorSize = lib.mkOption {
type = lib.types.int;
default = 32;
description = ''
XCURSOR_SIZE when accessibility is on. NixOS default is 24;
32 is a safer floor for low-vision users. Bump to 48 if the
user explicitly asks.
'';
};
};
gaming = {
enable = lib.mkEnableOption ''
Gaming preset: Steam (with remote-play firewall holes),
gamemode (CPU governor + nice on Steam launch via the user's
gamemode group), and flatpak. NOTE: flatpak's flathub remote
is not added declaratively after first boot, run
`flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo`.
The Hyprland fullscreen-on-Steam-launch window rule is a
separate roadmap item.
'';
};
containers = {
enable = lib.mkEnableOption ''
Rootless Podman with Docker compatibility (`docker` `podman`),
plus podman-compose, podman-tui and dive.
'';
};
virtualization = {
libvirt = {
enable = lib.mkEnableOption ''
libvirt daemon + virt-manager + OVMF. The user must be in the
`libvirtd` group.
'';
};
docker = {
enable = lib.mkEnableOption ''
Docker daemon + docker-compose. The user must be in the `docker`
group.
'';
};
};
keyring = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Auto-unlock GNOME Keyring at SDDM/Hyprland login and route SSH
keys through `gcr-ssh-agent`. Default on near-universal QoL
improvement.
'';
};
};
inputMethod = {
enable = lib.mkEnableOption ''
fcitx5 input method (CJK / IME). Wires NixOS's i18n.inputMethod and
autostarts fcitx5-daemon. Adds a small footprint when enabled, so
most users want this off.
'';
};
voxtype = {
enable = lib.mkEnableOption ''
voxtype voice-typing integration. NOTE: voxtype is not packaged in
nixpkgs when enabled, install voxtype yourself (e.g. via
`home.packages = [ (pkgs.callPackage {}) ]`). With this off the
SUPER+CTRL+X keybinding and waybar widget are no-ops.
'';
};
};
}