From 2f78e6fcba61ce81536d19e6c662e55ab272d539 Mon Sep 17 00:00:00 2001 From: hitsmaxft Date: Tue, 27 Jun 2023 09:12:51 +0800 Subject: [PATCH] antidote: static file move to /tmp Make antidote create static file path with hm hash_id in /tmp. --- modules/programs/antidote.nix | 30 ++++++++++++-------- tests/modules/programs/antidote/antidote.nix | 2 -- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/programs/antidote.nix b/modules/programs/antidote.nix index 2c4a14d1f..f1fa044ce 100644 --- a/modules/programs/antidote.nix +++ b/modules/programs/antidote.nix @@ -8,11 +8,13 @@ let (optionalString (config.programs.zsh.dotDir != null) (config.programs.zsh.dotDir + "/")) + file; - zPluginStr = with lib; - (pluginNames: - optionalString (pluginNames != [ ]) "${concatStrings (map (name: '' - ${name} - '') pluginNames)}"); + zPluginStr = (pluginNames: + optionalString (pluginNames != [ ]) "${concatStrings (map (name: '' + ${name} + '') pluginNames)}"); + + parseHashId = path: + elemAt (builtins.match "/nix/store/([a-zA-Z0-9]+)-.*" path) 0; in { meta.maintainers = [ maintainers.hitsmaxft ]; @@ -33,20 +35,24 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - - home.file."${relToDotDir ".zsh_plugins.txt"}".text = zPluginStr cfg.plugins; - - ### move zsh_plugins.txt - programs.zsh.initExtraBeforeCompInit = '' + programs.zsh.initExtraBeforeCompInit = let + configFiles = pkgs.runCommand "hm_antidote-files" { } '' + echo "${zPluginStr cfg.plugins}" > $out + ''; + hashId = parseHashId "${configFiles}"; + in '' ## home-manager/antidote begin : source ${cfg.package}/share/antidote/antidote.zsh ${optionalString cfg.useFriendlyNames "zstyle ':antidote:bundle' use-friendly-names 'yes'"} - bundlefile=$HOME/${relToDotDir ".zsh_plugins.txt"} + + bundlefile=${configFiles} zstyle ':antidote:bundle' file $bundlefile - staticfile=$HOME/${relToDotDir ".zsh_plugins.zsh"} + staticfile=/tmp/tmp_hm_zsh_plugins.zsh-${hashId} zstyle ':antidote:static' file $staticfile + antidote load $bundlefile $staticfile + ## home-manager/antidote end ''; }; diff --git a/tests/modules/programs/antidote/antidote.nix b/tests/modules/programs/antidote/antidote.nix index 04ba6dd56..3d8fff6a9 100644 --- a/tests/modules/programs/antidote/antidote.nix +++ b/tests/modules/programs/antidote/antidote.nix @@ -24,7 +24,5 @@ in { 'antidote load' assertFileContains home-files/${relToDotDirCustom}/.zshrc \ "zstyle ':antidote:bundle' use-friendly-names 'yes'" - assertFileContains home-files/${relToDotDirCustom}/.zsh_plugins.txt \ - 'zsh-users/zsh-autosuggestions' ''; }