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>
This commit is contained in:
@@ -1,47 +1,52 @@
|
||||
{ lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
# Defaults live in lib/state-schema.nix so they can't drift between this
|
||||
# file, core/system/options.nix, and core/home/state.nix's `or` fallbacks.
|
||||
schema = import ../../lib/state-schema.nix { inherit lib; };
|
||||
in
|
||||
{
|
||||
options.nomarchy = {
|
||||
toggles = {
|
||||
suspend = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
default = schema.home.suspend;
|
||||
description = "Whether to show suspend in system menu.";
|
||||
};
|
||||
screensaver = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
default = schema.home.screensaver;
|
||||
description = "Whether the screensaver is enabled.";
|
||||
};
|
||||
idle = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
default = schema.home.idle;
|
||||
description = "Whether the idle lock is enabled.";
|
||||
};
|
||||
nightlight = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
default = schema.home.nightlight;
|
||||
description = "Whether the nightlight is enabled.";
|
||||
};
|
||||
waybar = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
default = schema.home.waybar;
|
||||
description = "Whether the top bar is enabled.";
|
||||
};
|
||||
skipVsCodeTheme = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
default = schema.home.skipVsCodeTheme;
|
||||
description = "Whether to skip theme changes in VSCode.";
|
||||
};
|
||||
};
|
||||
nightlightTemperature = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 4000;
|
||||
default = schema.home.nightlightTemperature;
|
||||
description = "Temperature for the nightlight.";
|
||||
};
|
||||
theme = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "summer-night";
|
||||
default = schema.home.theme;
|
||||
description = "System theme name.";
|
||||
};
|
||||
formFactor = lib.mkOption {
|
||||
@@ -58,35 +63,35 @@
|
||||
};
|
||||
wallpaper = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
default = schema.home.wallpaper;
|
||||
description = "System wallpaper path.";
|
||||
};
|
||||
panelPosition = lib.mkOption {
|
||||
type = lib.types.enum [ "top" "bottom" ];
|
||||
default = "top";
|
||||
default = schema.home.panelPosition;
|
||||
description = "Waybar panel position.";
|
||||
};
|
||||
hyprland = {
|
||||
gaps_in = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 5;
|
||||
default = schema.home.hyprland.gaps_in;
|
||||
description = "Inner gaps for Hyprland.";
|
||||
};
|
||||
gaps_out = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 10;
|
||||
default = schema.home.hyprland.gaps_out;
|
||||
description = "Outer gaps for Hyprland.";
|
||||
};
|
||||
border_size = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 2;
|
||||
default = schema.home.hyprland.border_size;
|
||||
description = "Border size for Hyprland.";
|
||||
};
|
||||
};
|
||||
fonts = {
|
||||
monospace = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "JetBrainsMono Nerd Font";
|
||||
default = schema.home.font;
|
||||
description = "System monospace font.";
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
let
|
||||
nomarchyLib = import ../../lib { inherit lib; };
|
||||
# Single source of truth for default values when state.json is missing
|
||||
# a key. Both core/system/options.nix and core/home/options.nix read
|
||||
# from this same file — changing a default in one place updates
|
||||
# everywhere. (Was: each consumer hardcoded its own `or X` literal,
|
||||
# which is how the summer-night/nord split lived for so long.)
|
||||
schema = import ../../lib/state-schema.nix { inherit lib; };
|
||||
assetsPath = ../../themes/palettes;
|
||||
|
||||
# Read unified state from ~/.config/nomarchy/state.json
|
||||
@@ -11,31 +17,31 @@ in
|
||||
config = {
|
||||
nomarchy = {
|
||||
toggles = {
|
||||
suspend = togglesState.suspend or true;
|
||||
screensaver = togglesState.screensaver or true;
|
||||
idle = togglesState.idle or true;
|
||||
nightlight = togglesState.nightlight or false;
|
||||
waybar = togglesState.waybar or true;
|
||||
skipVsCodeTheme = togglesState.skipVsCodeTheme or false;
|
||||
suspend = togglesState.suspend or schema.home.suspend;
|
||||
screensaver = togglesState.screensaver or schema.home.screensaver;
|
||||
idle = togglesState.idle or schema.home.idle;
|
||||
nightlight = togglesState.nightlight or schema.home.nightlight;
|
||||
waybar = togglesState.waybar or schema.home.waybar;
|
||||
skipVsCodeTheme = togglesState.skipVsCodeTheme or schema.home.skipVsCodeTheme;
|
||||
};
|
||||
nightlightTemperature = togglesState.nightlightTemperature or 4000;
|
||||
theme = togglesState.theme or "nord";
|
||||
wallpaper = togglesState.wallpaper or "";
|
||||
panelPosition = togglesState.panelPosition or "top";
|
||||
nightlightTemperature = togglesState.nightlightTemperature or schema.home.nightlightTemperature;
|
||||
theme = togglesState.theme or schema.home.theme;
|
||||
wallpaper = togglesState.wallpaper or schema.home.wallpaper;
|
||||
panelPosition = togglesState.panelPosition or schema.home.panelPosition;
|
||||
hyprland = {
|
||||
gaps_in = togglesState.hyprland.gaps_in or 5;
|
||||
gaps_out = togglesState.hyprland.gaps_out or 10;
|
||||
border_size = togglesState.hyprland.border_size or 2;
|
||||
gaps_in = togglesState.hyprland.gaps_in or schema.home.hyprland.gaps_in;
|
||||
gaps_out = togglesState.hyprland.gaps_out or schema.home.hyprland.gaps_out;
|
||||
border_size = togglesState.hyprland.border_size or schema.home.hyprland.border_size;
|
||||
};
|
||||
fonts.monospace = togglesState.font or "JetBrainsMono Nerd Font";
|
||||
fonts.monospace = togglesState.font or schema.home.font;
|
||||
|
||||
# Derived properties from the theme directory
|
||||
isLightMode = nomarchyLib.isThemeLightMode {
|
||||
themeName = togglesState.theme or "nord";
|
||||
themeName = togglesState.theme or schema.home.theme;
|
||||
inherit assetsPath;
|
||||
};
|
||||
iconsTheme = nomarchyLib.getIconsTheme {
|
||||
themeName = togglesState.theme or "nord";
|
||||
themeName = togglesState.theme or schema.home.theme;
|
||||
inherit assetsPath;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
{ 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 = "DHCP";
|
||||
default = schema.system.dns;
|
||||
description = "Selected DNS provider.";
|
||||
};
|
||||
customDns = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [];
|
||||
default = schema.system.customDns;
|
||||
description = "List of custom DNS servers.";
|
||||
};
|
||||
wifi = {
|
||||
powersave = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
default = schema.system.wifi.powersave;
|
||||
description = "Whether to enable wifi power saving.";
|
||||
};
|
||||
};
|
||||
timezone = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "UTC";
|
||||
default = schema.system.timezone;
|
||||
description = "System timezone.";
|
||||
};
|
||||
formFactor = lib.mkOption {
|
||||
@@ -39,24 +44,24 @@
|
||||
features = {
|
||||
fingerprint = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
default = schema.system.features.fingerprint;
|
||||
description = "Whether to enable fingerprint support.";
|
||||
};
|
||||
fido2 = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
default = schema.system.features.fido2;
|
||||
description = "Whether to enable FIDO2 support.";
|
||||
};
|
||||
hybridGPU = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
default = schema.system.features.hybridGPU;
|
||||
description = "Whether to enable hybrid GPU support (supergfxd).";
|
||||
};
|
||||
};
|
||||
theme = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "nord";
|
||||
description = "Selected system theme. Matches lib/state-schema.nix and the installer-written state.json so a missing/blank state file lands on the same theme everywhere.";
|
||||
default = schema.system.theme;
|
||||
description = "Selected system theme.";
|
||||
};
|
||||
|
||||
# ----- Tier 1 system features (all opt-in, no behavioural change off) ---
|
||||
|
||||
Reference in New Issue
Block a user