{ lib, config, pkgs, ... }: let # --- Program definition --- programName = "zenbrowser"; # Assets (optional, empty if no config) assetPath = if builtins.pathExists ../../../assets/system/conf/${programName} then ../../../assets/system/conf/${programName} else null; 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.enableZenBrowser or false; # Default user fallback username = config.defaultUser or "henrov"; in { # --- Option --- options.enableZenBrowser = lib.mkEnableOption "Install Zen Browser"; # --- Config --- config = lib.mkIf enableProgram { # --- Deploy assets (if any) --- environment.etc."${programName}".source = assetPath; # --- System packages --- environment.systemPackages = [ pkgs.zen-browser ]; # --- Example systemd service to sync assets --- 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 cp -u "${assetPath}/$f" "/home/${username}/.config/${programName}/$f" done fi ''; }; restartTriggers = [ assetPath ]; path = []; }; }; }