mirror of
https://github.com/nix-community/home-manager
synced 2024-11-27 05:29:46 +01:00
fish: add plugin functionality
This commit is contained in:
parent
5be9aa417a
commit
b18d302d44
1 changed files with 82 additions and 2 deletions
|
@ -14,6 +14,39 @@ let
|
|||
mapAttrsToList (k: v: "alias ${k}='${v}'") cfg.shellAliases
|
||||
);
|
||||
|
||||
fileType = types.submodule (
|
||||
{ name, config, ... }: {
|
||||
options = {
|
||||
body = mkOption {
|
||||
default = null;
|
||||
type = types.nullOr types.lines;
|
||||
description = "Body of the function.";
|
||||
};
|
||||
|
||||
source = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
Path of the source file. The file name must not start
|
||||
with a period.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
source = mkIf (config.body != null) (
|
||||
mkDefault (pkgs.writeTextFile {
|
||||
inherit name;
|
||||
text = ''
|
||||
function ${name}
|
||||
${config.body}
|
||||
end
|
||||
'';
|
||||
executable = true;
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
|
||||
{
|
||||
|
@ -80,9 +113,27 @@ in
|
|||
type = types.lines;
|
||||
};
|
||||
};
|
||||
|
||||
programs.fish.plugins = mkOption {
|
||||
type = types.listOf types.package;
|
||||
default = [];
|
||||
description = ''
|
||||
The plugins to add to fish.
|
||||
Built with <varname>buildFishPlugin</varname>.
|
||||
Overrides manually installed ones.
|
||||
'';
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
programs.fish.functions = mkOption {
|
||||
type = types.attrsOf fileType;
|
||||
default = {};
|
||||
description = ''
|
||||
Functions to add to fish.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable (mkMerge [{
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
xdg.dataFile."fish/home-manager_generated_completions".source =
|
||||
|
@ -187,5 +238,34 @@ in
|
|||
set -g __fish_interactive_config_sourced 1
|
||||
end
|
||||
'';
|
||||
} {
|
||||
xdg.configFile = map (n: { target = "fish/functions/${n}.fish"; source = cfg.functions.${n}.source; }) (attrNames cfg.functions);
|
||||
} (
|
||||
let
|
||||
wrappedPkgVersion = lib.getVersion pkgs.fish;
|
||||
wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" pkgs.fish.name;
|
||||
dependencies = concatMap (p: p.dependencies) cfg.plugins;
|
||||
combinedPluginDrv = pkgs.buildEnv {
|
||||
name = "${wrappedPkgName}-plugins-${wrappedPkgVersion}";
|
||||
paths = cfg.plugins;
|
||||
postBuild = ''
|
||||
touch $out/setup.fish
|
||||
|
||||
if [ -d $out/functions ]; then
|
||||
echo "set fish_function_path \$fish_function_path[1] $out/functions \$fish_function_path[2..-1]" >> $out/setup.fish
|
||||
fi
|
||||
|
||||
if [ -d $out/completions ]; then
|
||||
echo "set fish_complete_path \$fish_complete_path[1] $out/completions \$fish_complete_path[2..-1]" >> $out/setup.fish
|
||||
fi
|
||||
|
||||
if [ -d $out/conf.d ]; then
|
||||
echo "source $out/conf.d/*.fish" >> $out/setup.fish
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in mkIf (length cfg.plugins > 0) {
|
||||
xdg.configFile."fish/conf.d/99plugins.fish".source = "${combinedPluginDrv}/setup.fish";
|
||||
home.packages = dependencies;
|
||||
})]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue