Skip to content

Instantly share code, notes, and snippets.

@Jomik
Created December 25, 2018 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jomik/d09e17b512c7052a03edb086f618b9c0 to your computer and use it in GitHub Desktop.
Save Jomik/d09e17b512c7052a03edb086f618b9c0 to your computer and use it in GitHub Desktop.
{ config, lib, pkgs,... }:
with lib;
let
cfg = config.programs.fish;
fileType = import ../../lib/file-type.nix { inherit lib pkgs; storePrefix = "fish_function"; };
mapAttrNames = f: set:
listToAttrs (map (attr: { name = f attr; value = set.${attr}; }) (attrNames set));
in {
options = {
programs.fish.plugins = mkOption {
type = types.listOf types.package;
default = [];
description = ''
The plugins to add to fish.
Built with <varname>buildPlugin</varname> or fetched from GitHub with <varname>pluginFromGitHub</varname>.
Overrides manually installed ones.
'';
};
programs.fish.functions = mkOption {
type = types.attrsOf types.submodule (
{ name, config, ... }: {
options = {
text = mkOption {
default = null;
type = types.nullOr types.lines;
description = "Text 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.text != null) (
mkDefault (pkgs.writeTextFile {
inherit name;
inherit (config) text;
executable = true;
destination = "/functions/${name}.fish";
})
);
};
}
);
default = {};
description = ''
Functions to add to fish.
'';
};
};
config = mkIf cfg.enable (
{
xdg.configFile = mapAttrNames (n: builtins.trace n "fish/functions/${n}.fish") cfg.functions;
} // (
let
wrappedPkgVersion = lib.getVersion pkgs.fish;
wrappedPkgName = lib.removeSuffix "-${wrappedPkgVersion}" pkgs.fish.name;
packages = concatMap (p: p.packages) cfg.plugins;
combinedPluginDrv = pkgs.buildEnv {
name = "${wrappedPkgName}-plugins-${wrappedPkgVersion}";
paths = cfg.plugins;
};
# combinedFunctionsDrv = pkgs.buildEnv {
# name = "${wrappedPkgName}-functions-${wrappedPkgVersion}";
# paths = map (n: cfg.functions.${n}.source) (attrNames cfg.functions);
# };
in {
xdg.configFile."fish/conf.d/00plugins.fish".text = ''
set -x fish_function_path ${combinedPluginDrv}/functions $fish_function_path
set -x fish_complete_path ${combinedPluginDrv}/completions $fish_complete_path
source ${combinedPluginDrv}/conf.d/*.fish
'';
# xdg.configFile."fish/conf.d/01functions.fish".text = ''
# set -x fish_function_path ${combinedFunctionsDrv}/functions $fish_function_path
# '';
home.packages = packages;
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment