{ lib, config, ... }: let # --- Module variables --- moduleName = "stylix"; username = config.defaultUser or "henrov"; # Assets directory assetPath = if builtins.pathExists ../../../assets/system/theming/${moduleName} then ../../../assets/system/theming/${moduleName} else null; # Read all files if assets exist programFiles = if assetPath != null then builtins.readDir assetPath else {}; files = lib.genAttrs (builtins.attrNames programFiles) (name: { src = "${assetPath}/${name}"; }); # Top-level toggle for this module enableProgram = config.enableStylix or false; # Stylix self-contained configuration stylixCfg = { enable = true; base16Scheme = ../../../assets/system/theming/stylix/catppuccin-mocha.yaml; image = ../../../assets/hyprland/wallpaperstuff/pictures/wall1.jpg; polarity = "dark"; cursor = { package = "phinger-cursors"; # symbolic reference name = "phinger-cursors-light"; size = 24; }; fonts = { monospace = { package = "nerd-fonts-fira-code"; name = "Fira Code Nerd Font"; }; sansSerif = { package = "lato"; name = "Lato"; }; }; icons = { enable = true; package = "papirus-icon-theme"; dark = "Papirus-Dark"; light = "Papirus-Light"; }; }; in { # --- Top-level toggle option --- options.enableStylix = lib.mkEnableOption "Enable Stylix system theming"; # --- Only apply configuration if enabled --- config = lib.mkIf enableProgram { # --- Stylix dendritic app definition --- stylixModule = { enable = true; assetsDir = assetPath; files = files; user = username; theme = "catppuccin-mocha"; polarity = "dark"; }; # --- Stylix theming config --- stylix = stylixCfg; # --- Optional wallpaper helper (dendritic) --- wallpaperHelper = { enable = true; packages = [ "feh" "st" ]; # symbolic package names }; # --- Cursor environment variables --- home-manager.users.${username}.home.sessionVariables = { XCURSOR_THEME = stylixCfg.cursor.name; XCURSOR_SIZE = toString stylixCfg.cursor.size; HYPRCURSOR_THEME = stylixCfg.cursor.name; HYPRCURSOR_SIZE = toString stylixCfg.cursor.size; }; # --- Optional systemd service to sync assets --- systemd.services."${moduleName}-sync" = { description = "Sync ${moduleName} configuration assets"; wantedBy = [ "multi-user.target" ]; wants = [ "network-online.target" ]; after = [ "network-online.target" ]; serviceConfig = { Type = "oneshot"; ExecStart = '' set -euo pipefail if [ -d "${assetPath}" ]; then for f in ${lib.concatStringsSep " " (builtins.attrNames files)}; do cp -u "${assetPath}/$f" "/home/${username}/.config/${moduleName}/$f" done fi ''; }; restartTriggers = [ assetPath ]; path = []; }; }; }