1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-11 09:13:38 +02:00

fish: add plugin functionality

This commit is contained in:
Jonas Holst Damtoft 2019-03-23 21:09:03 +01:00 committed by Robert Helgesson
parent 5be9aa417a
commit b18d302d44
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89

View File

@ -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.
'';
};
programs.fish.functions = mkOption {
type = types.attrsOf fileType;
default = {};
description = ''
Functions to add to fish.
'';
};
};
config = mkIf cfg.enable {
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;
})]);
}