Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion doc/hooks/installShellFiles.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,38 @@ The `installShellCompletion` function takes one or more paths to shell completio
installShellCompletion --zsh --name _foobar share/completions.zsh
# implicit behavior
installShellCompletion share/completions/foobar.{bash,fish,zsh}
# using named fd
'';
}
```

When generating completions requires the execution of programs,
it's necessary to disable this process during cross-compilation.
This is because the current build platform may not be able to run binaries of the host platform.

```nix
{
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
# Utilizing named file descriptor
installShellCompletion --cmd foobar \
--bash <($out/bin/foobar --bash-completion) \
--fish <($out/bin/foobar --fish-completion) \
--zsh <($out/bin/foobar --zsh-completion)
'';
}
```

Copy link
Member

@SFrijters SFrijters Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people have spoken out against this solution before #316749 (comment) and below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot quite follow the reasoning in this thread though. Qemu is not that bad to have in your build closure. It should be already compiled anyway. But I think it's harder to test, so I personally prefer if contributor at least remove this completion for cross compilation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion either way, just trying to tie all the discussions in various places together (and hopefully the bikeshedding will converge on something).

Separate question: why is this in preFixup? Is that because it's before wrapping happens?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion here. I let you let write the documentation than.
Just ping me on the review.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mic92 #325591 was already merged before I got to respond to your comment.

An alternative to disabling this postInstall step, is to use the emulator package if available:
The emulator expects a binary executable as an argument,
so you may have to prefix the script interpreter executable or
run the unwrapped version of the program in case the program is wrapped with a shell wrapper.

```
{
preFixup = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) ''
installShellCompletion --cmd rg \
--bash <(${stdenv.hostPlatform.emulator buildPackages} $out/bin/rg --generate complete-bash) \
--fish <(${stdenv.hostPlatform.emulator buildPackages} $out/bin/rg --generate complete-fish) \
--zsh <(${stdenv.hostPlatform.emulator buildPackages} $out/bin/rg --generate complete-zsh)
'';
}
```