From 64f05a5771ed619ca092e85033196b25fe73d695 Mon Sep 17 00:00:00 2001 From: diniamo Date: Wed, 7 Aug 2024 16:21:57 +0200 Subject: [PATCH] fish: install plugin files Fish plugin files are now installed directly into the config directory instead of being sourced. This is needed because sourcing breaks attaching event listeners using `functions --query`, which sponge requires for example. --- modules/programs/fish.nix | 110 ++++++++++++-------------------------- 1 file changed, 35 insertions(+), 75 deletions(-) diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index fc11e5124..3373defe3 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -6,29 +6,6 @@ let cfg = config.programs.fish; - pluginModule = types.submodule ({ config, ... }: { - options = { - src = mkOption { - type = types.path; - description = '' - Path to the plugin folder. - - Relevant pieces will be added to the fish function path and - the completion path. The {file}`init.fish` and - {file}`key_binding.fish` files are sourced if - they exist. - ''; - }; - - name = mkOption { - type = types.str; - description = '' - The name of the plugin. - ''; - }; - }; - }); - functionModule = types.submodule { options = { body = mkOption { @@ -326,36 +303,36 @@ in { }; programs.fish.plugins = mkOption { - type = types.listOf pluginModule; + type = types.listOf types.path; default = [ ]; example = literalExpression '' [ - { - name = "z"; - src = pkgs.fetchFromGitHub { - owner = "jethrokuan"; - repo = "z"; - rev = "ddeb28a7b6a1f0ec6dae40c636e5ca4908ad160a"; - sha256 = "0c5i7sdrsp0q3vbziqzdyqn4fmp235ax4mn4zslrswvn8g3fvdyh"; - }; - } + (pkgs.fetchFromGitHub { + owner = "jethrokuan"; + repo = "z"; + rev = "ddeb28a7b6a1f0ec6dae40c636e5ca4908ad160a"; + sha256 = "0c5i7sdrsp0q3vbziqzdyqn4fmp235ax4mn4zslrswvn8g3fvdyh"; + }) # oh-my-fish plugins are stored in their own repositories, which # makes them simple to import into home-manager. - { - name = "fasd"; - src = pkgs.fetchFromGitHub { - owner = "oh-my-fish"; - repo = "plugin-fasd"; - rev = "38a5b6b6011106092009549e52249c6d6f501fba"; - sha256 = "06v37hqy5yrv5a6ssd1p3cjd9y3hnp19d3ab7dag56fs1qmgyhbs"; - }; - } + (pkgs.fetchFromGitHub { + owner = "oh-my-fish"; + repo = "plugin-fasd"; + rev = "38a5b6b6011106092009549e52249c6d6f501fba"; + sha256 = "06v37hqy5yrv5a6ssd1p3cjd9y3hnp19d3ab7dag56fs1qmgyhbs"; + }); + + pkgs.fishPlugins.tide.src ] ''; description = '' - The plugins to source in - {file}`conf.d/99plugins.fish`. + The plugins to install. + + It's important to pass the source files directly, + instead of the derivations in nixpkgs. You can still + use plugins from nixpkgs by accessing their `src` attribute, + as seen in the example. ''; }; @@ -516,37 +493,20 @@ in { # Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load # in the paths and any initialization scripts. (mkIf (length cfg.plugins > 0) { - xdg.configFile = mkMerge ((map (plugin: { - "fish/conf.d/plugin-${plugin.name}.fish".source = - fishIndent "${plugin.name}.fish" '' - # Plugin ${plugin.name} - set -l plugin_dir ${plugin.src} - - # Set paths to import plugin components - if test -d $plugin_dir/functions - set fish_function_path $fish_function_path[1] $plugin_dir/functions $fish_function_path[2..-1] - end - - if test -d $plugin_dir/completions - set fish_complete_path $fish_complete_path[1] $plugin_dir/completions $fish_complete_path[2..-1] - end - - # Source initialization code if it exists. - if test -d $plugin_dir/conf.d - for f in $plugin_dir/conf.d/*.fish - source $f - end - end - - if test -f $plugin_dir/key_bindings.fish - source $plugin_dir/key_bindings.fish - end - - if test -f $plugin_dir/init.fish - source $plugin_dir/init.fish - end - ''; - }) cfg.plugins)); + xdg.configFile = mkMerge (flatten (map (src: + let + mkPluginConfig = src: dir: + let path = "${src}/${dir}"; + in if pathExists path then + map (file: { "fish/${dir}/${file}".source = "${path}/${file}"; }) + (attrNames (builtins.readDir path)) + else + [ ]; + in [ + (mkPluginConfig src "functions") + (mkPluginConfig src "completions") + (mkPluginConfig src "conf.d") + ]) cfg.plugins)); }) ]); }