{ lib, config, ... }: let # --- Program definition --- programName = "wofi"; # Path to assets assetPath = ../../../assets/system/conf/${programName}; # Generate file mappings programFiles = if builtins.pathExists assetPath then builtins.readDir assetPath else {}; files = lib.genAttrs (builtins.attrNames programFiles) (name: { src = "${assetPath}/${name}"; }); # Top-level toggle for this module enableProgram = config.enableWofi or false; # Default user username = config.defaultUser or "henrov"; in { # --- Module option --- options.enableWofi = lib.mkEnableOption "Enable Wofi terminal launcher"; # --- Config --- config = lib.mkIf enableProgram { # --- Deploy assets to ~/.config/wofi --- environment.etc."${programName}".source = assetPath; # --- Optional systemd service to sync config --- systemd.services."${programName}-sync" = { description = "Sync ${programName} configuration files"; 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 mkdir -p "/home/${username}/.config/${programName}" cp -u "${assetPath}/$f" "/home/${username}/.config/${programName}/$f" done fi ''; }; restartTriggers = [ assetPath ]; path = []; }; }; }