Files
Nomarchy/lib/default.nix
Bernardo Magri 877da19770 feat: make VM and live ISO match an installed Nomarchy
- Migrate VM and graphical ISO to home-manager.nixosModules.home-manager;
  drop the standalone-HM sudo-based activation script (ran HM against
  /root because HOME wasn't reset) in flake.nix, core/system/vm-guest.nix,
  hosts/live-iso.nix.
- Run swaybg as nomarchy-wallpaper.service instead of a silent Hyprland
  exec-once so failures surface in systemctl.
- Skip the battery monitor unit on hosts without /sys/class/power_supply/BAT*
  (VMs, desktops).
- Don't wrap walker --dmenu in uwsm-app; redirect setsid background std-fds
  in nomarchy-launch-walker so $(menu ...) in nomarchy-menu doesn't hang.
- Restart waybar/walker via systemctl --user rather than pkill + uwsm-app
  to stop the post-theme-switch color race.
- Wire nomarchy-restart-walker/-waybar into nomarchy-theme-set so themes
  that only change the imported CSS reload correctly.
- Waybar: pin #custom-nomarchy to the Nomarchy font and use the U+F000
  codepoint so the logo shows across all themes.
- Auto-install the correct icon-theme package per palette via a new
  nomarchyLib.iconThemePackage helper in lib/default.nix; Everforest now
  actually renders for summer-night.
- Pre-cache every theme's HM generation: new packages.allThemeVariants
  flake output and nomarchy-themes-prebuild script so theme switches are
  cache-only (no Stylix rebuild, no downloads).
- Add nomarchy-test-live-iso to boot the graphical ISO in QEMU the same
  way nomarchy-test-vm does, with virtio-gpu support added to live-iso.nix.
- Installer-generated home.nix/system.nix now ship a curated, commented
  app menu (btop/fastfetch/chromium on by default) plus optional system
  services (Docker, libvirtd, Tailscale, Syncthing, Flatpak, Steam).
- nomarchy-test-vm now wipes the stale nomarchy.qcow2 before launch.
- Remove obsolete GEMINI.md and PLAN.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-24 18:20:54 +01:00

112 lines
3.5 KiB
Nix

# Nomarchy Shared Library
# Centralized utilities to reduce code duplication across modules
{ lib }:
let
# Import theme palettes once - used by multiple modules
palettes = import ./../themes/palettes;
# Unified state reading function
# Handles both JSON and plain text files with graceful fallbacks
readState = { file, default }:
if builtins.pathExists file then
let
content = builtins.readFile file;
cleanContent = lib.removeSuffix "\n" content;
in
if lib.hasSuffix ".json" (toString file) then
builtins.fromJSON cleanContent
else
cleanContent
else
default;
# Read home state from unified location
readHomeState = homeDirectory:
readState {
file = "${homeDirectory}/.config/nomarchy/state.json";
default = {};
};
# Read system state
readSystemState =
readState {
file = "/etc/nixos/state.json";
default = {};
};
# Resolve wallpaper path with fallback
# Returns either the user-specified wallpaper or a default from the theme
resolveWallpaper = { wallpaperPath, themeName, assetsPath }:
if wallpaperPath != "" then
wallpaperPath
else
let
themeBackgrounds = assetsPath + "/${themeName}/backgrounds";
defaultBackground = assetsPath + "/catppuccin/backgrounds/1-totoro.png";
in
if builtins.pathExists themeBackgrounds then
let
backgrounds = builtins.attrNames (builtins.readDir themeBackgrounds);
in
if backgrounds != [] then
"${themeBackgrounds}/${builtins.head (builtins.sort (a: b: a < b) backgrounds)}"
else
defaultBackground
else
defaultBackground;
# Get current palette from theme name
getPalette = themeName:
(palettes.${themeName} or palettes.nord).palette;
# Get full color scheme from theme name
getColorScheme = themeName:
palettes.${themeName} or palettes.nord;
# Check if a theme is light mode
isThemeLightMode = { themeName, assetsPath }:
builtins.pathExists (assetsPath + "/${themeName}/light.mode");
# Get icons theme for a given theme
getIconsTheme = { themeName, assetsPath, default ? "Yaru-blue" }:
let
iconsFile = assetsPath + "/${themeName}/icons.theme";
in
if builtins.pathExists iconsFile then
lib.removeSuffix "\n" (builtins.readFile iconsFile)
else
default;
# Map an icon-theme name (as declared in a palette's icons.theme file) to
# the nixpkgs attribute that ships it. Anything unknown falls back to
# yaru-theme so GTK still has a working default.
#
# When adding a palette that uses a new icon family, extend this mapping
# so `nomarchy-theme-set <name>` auto-installs the matching package.
iconThemePackage = { iconsTheme, pkgs }:
if lib.hasPrefix "Yaru" iconsTheme then pkgs.yaru-theme
else if lib.hasPrefix "Everforest" iconsTheme then pkgs.everforest-gtk-theme
else if lib.hasPrefix "Papirus" iconsTheme then pkgs.papirus-icon-theme
else if lib.hasPrefix "Adwaita" iconsTheme then pkgs.adwaita-icon-theme
else if lib.hasPrefix "breeze" iconsTheme || lib.hasPrefix "Breeze" iconsTheme then pkgs.kdePackages.breeze-icons
else pkgs.yaru-theme;
# Get list of available theme names
themeNames = builtins.attrNames palettes;
in {
inherit
palettes
readState
readHomeState
readSystemState
resolveWallpaper
getPalette
getColorScheme
isThemeLightMode
getIconsTheme
iconThemePackage
themeNames;
}