diff --git a/modules/desktop/shells/dms/home-manager/default.nix b/modules/desktop/shells/dms/home-manager/default.nix index c54399a..e708558 100644 --- a/modules/desktop/shells/dms/home-manager/default.nix +++ b/modules/desktop/shells/dms/home-manager/default.nix @@ -3,11 +3,36 @@ config, pkgs, lib, + osConfig ? { }, ... }: let home = config.home.homeDirectory; cfg = config.dms; gpuTempEnabled = cfg.enableGpuTemp; + hyprlandEnabled = lib.attrByPath [ "chiasson" "desktop" "hyprland" "enable" ] false osConfig; + discordEnabled = lib.attrByPath [ "chiasson" "home" "apps" "discord" "enable" ] false config; + ohMyPoshEnabled = config.programs.oh-my-posh.enable or false; + matugenOutputDirs = + lib.optionals hyprlandEnabled [ "${home}/.config/hypr" ] + ++ lib.optionals ohMyPoshEnabled [ "${home}/.config/oh-my-posh" ] + ++ lib.optionals discordEnabled [ "${home}/.config/vesktop/themes" ]; + ensureMatugenOutputDirsScript = pkgs.writeShellScript "dms-ensure-matugen-output-dirs" '' + set -euo pipefail + ${lib.concatStringsSep "\n" (map (dir: "mkdir -p ${lib.escapeShellArg dir}") matugenOutputDirs)} + ${lib.optionalString ohMyPoshEnabled '' + dest="$HOME/.config/oh-my-posh/theme.omp.json" + template="$HOME/.config/matugen/templates/ohmyposh-theme.omp.json" + # matugen writes output_path in place; HM symlinks into the store are read-only and go stale. + if [ -L "$dest" ] || { [ -e "$dest" ] && ! [ -f "$dest" ]; }; then + rm -f "$dest" + fi + if [ ! -f "$dest" ]; then + # Seed from our matugen template (same generation closure), not programs.oh-my-posh.package + # which can reference a GC'd store path after profile churn. + cp -L "$template" "$dest" + fi + ''} + ''; obsidianSnippetsDir = cfg.obsidianSnippetsDir; # legacy single path obsidianSnippetDirs = let @@ -541,29 +566,40 @@ in { }; }; + # matugen won't create missing output_path parents; run before DMS theme generation. + systemd.user.services.dms.serviceConfig.ExecStartPre = + lib.mkOrder 100 "${ensureMatugenOutputDirsScript}"; + # DMS / matugen custom templates. # # DMS docs (custom templates): https://danklinux.com/docs/dankmaterialshell/application-themes#custom-matugen-templates xdg.configFile."matugen/config.toml".text = '' [config] - + '' + + lib.optionalString hyprlandEnabled '' [templates.hyprland] input_path = '${home}/.config/matugen/templates/hyprland-colors.conf' output_path = '${home}/.config/hypr/colors.conf' + '' + + '' [templates.kdeglobals] input_path = '${home}/.config/matugen/templates/kdeglobals.conf' output_path = '${home}/.config/kdeglobals' + '' + + lib.optionalString ohMyPoshEnabled '' [templates.ohmyposh] input_path = '${home}/.config/matugen/templates/ohmyposh-theme.omp.json' output_path = '${home}/.config/oh-my-posh/theme.omp.json' + '' + + lib.optionalString discordEnabled '' [templates.dank-discord] input_path = '${home}/.config/matugen/templates/dank-discord.css' output_path = '${home}/.config/vesktop/themes/dank-discord.css' - '' + '' + lib.optionalString (obsidianSnippetDirs != []) ( lib.concatStringsSep "\n" ( lib.lists.imap0 (i: snippetDir: '' @@ -576,6 +612,10 @@ in { ) ; + home.activation.dmsEnsureMatugenOutputDirs = lib.hm.dag.entryAfter ["writeBoundary"] '' + ${ensureMatugenOutputDirsScript} + ''; + # Obsidian snippet dirs for matugen: mkdir here instead of tmpfiles (no chmod fights on weird mounts). home.activation.dmsEnsureObsidianSnippetDirs = lib.hm.dag.entryAfter ["writeBoundary"] ( let @@ -1107,14 +1147,8 @@ in { } ''; } - (lib.mkIf (lib.attrByPath [ "chiasson" "home" "shell" "ohMyPosh" "enable" ] false config) { - # Matugen overwrites this at runtime; seed a stock theme so `oh-my-posh init fish` works before DMS runs matugen. - xdg.configFile."oh-my-posh/theme.omp.json".source = - let - ompTheme = config.chiasson.home.shell.ohMyPosh.builtinTheme or "jandedobbeleer"; - in - "${config.programs.oh-my-posh.package}/themes/${ompTheme}.omp.json"; - # Same path as matugen `[templates.ohmyposh]` output in `programs.dank-material-shell` config. + (lib.mkIf ohMyPoshEnabled { + # Same path as matugen `[templates.ohmyposh]`; seeded as a real file by `ensureMatugenOutputDirsScript`. programs.oh-my-posh = { useTheme = lib.mkForce null; configFile = lib.mkForce "${config.xdg.configHome}/oh-my-posh/theme.omp.json";