1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-31 04:04:32 +00:00

fish: keep all fish-completions packages around

...even empty ones.

For packages in `home.packages` with no Fish completions, we build an
empty directory that is not included in our runtime closure (because we
build a collection of symlinks to their contents: if there are no
contents, there is nothing to symlink). This means these empty
completion packages get garbage-collected by Nix. They are not that
expensive to rebuild but there can be enough of them it adds up, and any
change to any package in `home.packages` is enough to trigger a rebuild.

Fix this by forcing a dependency on all of them. Since we already
depended on them anyway if they were non-empty, this only adds
dependencies on empty directories (so should not significantly affect
storage space).

Fixes #6157.
This commit is contained in:
Marien Zwart 2025-03-02 21:35:26 +11:00
parent c3a1b97a1d
commit c56d3df0af
No known key found for this signature in database

View file

@ -408,7 +408,35 @@ in {
config = mkIf cfg.enable (mkMerge [
{ home.packages = [ cfg.package ]; }
(mkIf cfg.generateCompletions {
(mkIf cfg.generateCompletions (let
generateCompletions = let
getName = attrs:
attrs.name or "${attrs.pname or "«pname-missing»"}-${
attrs.version or "«version-missing»"
}";
in package:
pkgs.runCommand "${getName package}-fish-completions" {
srcs = [ package ] ++ filter (p: p != null)
(builtins.map (outName: package.${outName} or null)
config.home.extraOutputsToInstall);
nativeBuildInputs = [ pkgs.python3 ];
buildInputs = [ cfg.package ];
preferLocalBuild = true;
} ''
mkdir -p $out
for src in $srcs; do
if [ -d $src/share/man ]; then
find -L $src/share/man -type f \
| xargs python ${cfg.package}/share/fish/tools/create_manpage_completions.py --directory $out \
> /dev/null
fi
done
'';
allCompletions =
let cmp = (a: b: (a.meta.priority or 0) > (b.meta.priority or 0));
in map generateCompletions (sort cmp config.home.packages);
in {
# Support completion for `man` by building a cache for `apropos`.
programs.man.generateCaches = mkDefault true;
@ -431,36 +459,16 @@ in {
${postBuild}
'';
generateCompletions = let
getName = attrs:
attrs.name or "${attrs.pname or "«pname-missing»"}-${
attrs.version or "«version-missing»"
}";
in package:
pkgs.runCommand "${getName package}-fish-completions" {
srcs = [ package ] ++ filter (p: p != null)
(builtins.map (outName: package.${outName} or null)
config.home.extraOutputsToInstall);
nativeBuildInputs = [ pkgs.python3 ];
buildInputs = [ cfg.package ];
preferLocalBuild = true;
} ''
mkdir -p $out
for src in $srcs; do
if [ -d $src/share/man ]; then
find -L $src/share/man -type f \
| xargs python ${cfg.package}/share/fish/tools/create_manpage_completions.py --directory $out \
> /dev/null
fi
done
'';
in destructiveSymlinkJoin {
name = "${config.home.username}-fish-completions";
paths =
let cmp = (a: b: (a.meta.priority or 0) > (b.meta.priority or 0));
in map generateCompletions (sort cmp config.home.packages);
paths = allCompletions;
};
# For packages with no Fish completions, generateCompletions will build an empty directory,
# which means they will not be in our runtime closure. Force a dependency so these do not get
# constantly rebuilt.
home.extraDependencies = allCompletions;
programs.fish.interactiveShellInit = ''
# add completions generated by Home Manager to $fish_complete_path
begin
@ -472,7 +480,7 @@ in {
set fish_complete_path $prev "${config.xdg.dataHome}/fish/home-manager_generated_completions" $post
end
'';
})
}))
{
xdg.configFile."fish/config.fish".source = fishIndent "config.fish" ''