zsh: option to define autoloadable site-functions (#7611)

Add an option to the Zsh module that allows defining autoloadable site functions.
This commit is contained in:
Benedikt M. Rips 2025-08-05 21:03:10 +02:00 committed by GitHub
parent c5d7e95739
commit 36ad7d25fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 0 deletions

View file

@ -325,6 +325,23 @@ in
To unset an option, prefix it with "NO_".
'';
};
siteFunctions = mkOption {
type = types.attrsOf types.lines;
default = { };
description = ''
Functions that are added to the Zsh environment and are subject to
{command}`autoload`ing. The key is the name and the value is the body of
the function to be autoloaded.
They are also already marked for autoloading through `autoload -Uz`.
'';
example = {
mkcd = ''
mkdir --parents "$1" && cd "$1"
'';
};
};
};
};
@ -409,6 +426,15 @@ in
'';
})
(lib.mkIf (cfg.siteFunctions != { }) {
home.packages = lib.mapAttrsToList (
name: pkgs.writeTextDir "share/zsh/site-functions/${name}"
) cfg.siteFunctions;
programs.zsh.initContent = concatStringsSep " " (
[ "autoload -Uz" ] ++ lib.attrNames cfg.siteFunctions
);
})
{
home.file."${dotDirRel}/.zshenv".text = ''
# Environment variables