fix(theme): #66 fail-closed theme-state errors at mkFlake/read
Missing, empty, or non-object theme-state.json now throws a short message pointing at the template and `nomarchy-theme-sync validate` instead of a raw readFile/fromJSON stack. Shared reader: modules/theme-state-read.nix — wired in theme.nix, plymouth/timezone/ hardware, and lib.mkFlake (seq-forced early gate). Field-level schema in theme.nix kept; unknown border roles still fail there; resolveColor no longer falls through on missing palette keys. Defaults added for settings.displayProfile / displayProfileAuto. Verified: V0 nix flake check --no-build; negative evals (missing, empty, [], bad border role); good-path template mode + displayProfile defaults.
This commit is contained in:
@@ -18,7 +18,11 @@
|
||||
let
|
||||
cfg = config.nomarchy;
|
||||
|
||||
themeState = builtins.fromJSON (builtins.readFile cfg.stateFile);
|
||||
# Fail-closed load: missing / empty / non-object get a short pointer at
|
||||
# the template + `nomarchy-theme-sync validate`, not a raw readFile stack
|
||||
# from deep inside a consumer (nightlight, hyprland, …). Field-level
|
||||
# checks below still run on the merged result.
|
||||
themeState = import ../theme-state-read.nix { inherit lib; } cfg.stateFile;
|
||||
|
||||
# Defaults guarantee evaluation succeeds on a sparse or older state
|
||||
# file (e.g. one written before a schema field was added). The shipped
|
||||
@@ -64,6 +68,8 @@ let
|
||||
# rebuild. settings.monitors: per-output resolutions the Display menu
|
||||
# remembers (output-name -> "WxH@R"), overlaid onto nomarchy.monitors by
|
||||
# name in hyprland.nix — the monitor twin of the keyboard graduation.
|
||||
# settings.displayProfile / displayProfileAuto: active named layout +
|
||||
# auto-switch on plug events (hyprland.nix / Display menu).
|
||||
# Defaulted so a sparse/older state file still evaluates; nomarchy.settings
|
||||
# exposes them.
|
||||
settings = {
|
||||
@@ -74,6 +80,8 @@ let
|
||||
# service, but the flag lives here so both sides read one source — the
|
||||
# home side gates the Waybar-refresh watcher (timezone.nix) on it.
|
||||
autoTimezone = false;
|
||||
displayProfile = "";
|
||||
displayProfileAuto = false;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -135,11 +143,18 @@ let
|
||||
`nomarchy-theme-sync apply boreal`.'';
|
||||
|
||||
# A border value is a palette key (look it up in colors) unless it's
|
||||
# already a literal hex; unknown keys fall through to the raw string.
|
||||
resolveColor = v: if lib.hasPrefix "#" v then v else parsed.colors.${v} or v;
|
||||
# already a literal hex. Unknown roles are rejected by the field checks
|
||||
# above; resolve only runs on a validated state.
|
||||
resolveColor = v:
|
||||
if lib.hasPrefix "#" v then v
|
||||
else parsed.colors.${v} or (throw ''
|
||||
|
||||
Nomarchy: border role "${v}" is not in the palette (colors.*).
|
||||
Use one of: ${lib.concatStringsSep ", " colorRoles}
|
||||
or a literal "#RRGGBB". Validate with: nomarchy-theme-sync validate'');
|
||||
border = {
|
||||
active = resolveColor parsed.border.active;
|
||||
inactive = resolveColor parsed.border.inactive;
|
||||
active = resolveColor checked.border.active;
|
||||
inactive = resolveColor checked.border.inactive;
|
||||
};
|
||||
|
||||
# Resolve the icon theme once and expose it on nomarchy.theme so both
|
||||
|
||||
Reference in New Issue
Block a user