New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/fish: generate autocompletions from man pages #56446
Conversation
bbbf634
to
f051427
Compare
Here's the actual diff (excluding test), compared to the state before the revert: (Made this by squashing the revert commit and a commit of these changes together.) diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix
index 03d6c26c8c8..1fe59407943 100644
--- a/nixos/modules/programs/fish.nix
+++ b/nixos/modules/programs/fish.nix
@@ -182,11 +182,38 @@ in
environment.etc."fish/generated_completions".source =
let
+ patchedGenerator = pkgs.stdenv.mkDerivation {
+ name = "fish_patched-completion-generator";
+ srcs = [
+ "${pkgs.fish}/share/fish/tools/create_manpage_completions.py"
+ "${pkgs.fish}/share/fish/tools/deroff.py"
+ ];
+ unpackCmd = "cp $curSrc $(basename $curSrc)";
+ sourceRoot = ".";
+ patches = [ (pkgs.writeText "fish_completion-generator_patch" ''
+ --- a/create_manpage_completions.py
+ +++ b/create_manpage_completions.py
+ @@ -776,8 +776,6 @@ def parse_manpage_at_path(manpage_path, output_directory):
+
+ built_command_output.insert(0, "# " + CMDNAME)
+
+ - # Output the magic word Autogenerated so we can tell if we can overwrite this
+ - built_command_output.insert(1, "# Autogenerated from man page " + manpage_path)
+ # built_command_output.insert(2, "# using " + parser.__class__.__name__) # XXX MISATTRIBUTES THE CULPABILE PARSER! Was really using Type2 but reporting TypeDeroffManParser
+
+ for line in built_command_output:
+ '') ];
+ dontBuild = true;
+ installPhase = ''
+ mkdir -p $out
+ cp * $out/
+ '';
+ };
generateCompletions = package: pkgs.runCommand
- "${package.name}-fish-completions"
+ "${package.name}_fish-completions"
(
{
- src = package;
+ inherit package;
nativeBuildInputs = [ pkgs.python3 ];
buildInputs = [ pkgs.fish ];
preferLocalBuild = true;
@@ -196,13 +223,14 @@ in
)
''
mkdir -p $out
- if [ -d $src/share/man ]; then
- find $src/share/man -type f | xargs python ${pkgs.fish}/share/fish/tools/create_manpage_completions.py --directory $out >/dev/null
+ if [ -d $package/share/man ]; then
+ find $package/share/man -type f | xargs python ${patchedGenerator}/create_manpage_completions.py --directory $out >/dev/null
fi
'';
in
pkgs.buildEnv {
name = "system-fish-completions";
+ ignoreCollisions = true;
paths = map generateCompletions config.environment.systemPackages;
};
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix
index 65227857a38..2ddb54bcc3d 100644
--- a/nixos/tests/all-tests.nix
+++ b/nixos/tests/all-tests.nix
@@ -74,6 +74,7 @@ in
ferm = handleTest ./ferm.nix {};
firefox = handleTest ./firefox.nix {};
firewall = handleTest ./firewall.nix {};
+ fish = handleTest ./fish.nix {};
flannel = handleTestOn ["x86_64-linux"] ./flannel.nix {};
flatpak = handleTest ./flatpak.nix {};
fsck = handleTest ./fsck.nix {}; |
f051427
to
79c7e7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this!
I can confirm that this PR produces no errors with my current system configuration. |
79c7e7f
to
bc6db9c
Compare
You forgot to |
bc6db9c
to
407c24d
Compare
407c24d
to
3731835
Compare
Argh. Fixed. |
Also resolves the issue with the collisions for me. |
I was wondering if the generation could be implemented in a way such that the completion are in a single derivation. Currently I'm seeings hunders of |
This is fundamentally a tradeoff between noise and performance on incremental package additions to the environment - creating completions for everything in Python takes a significant amount of time which I did not want to burden every new package installation with. |
I didn't think of that, you are right: a single derivation would have to be rebuilt every time and it's definitely worse.
Probably not, as I said it's not a big deal. Thank you for replying and sorry for the trouble. |
Motivation for this change
#52464, but fixed.
Any colliding completions will override just as the system path does, but we prevent generating collision warnings for completions that are actually identical by not writing the source path into the completion file.
Also we have a small test now that should cover the effect of this PR.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)