mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-11-09 16:18:34 +01:00
This treewide conditions execution of the built applications for the purpose of generating shell completions behind `stdenv.buildPlatform.canExecute stdenv.hostPlatform`, which helps cross. This is a common issue I spot during review, let's prevent copy-paste errors by fixing it treewide.
Candidates were located with:
```shell
rg 'installShellCompletion' -l -tnix | xargs grep -F 'stdenv.buildPlatform.canExecute stdenv.hostPlatform' -L
```
Then I migrated the obvious cases which would not require a rebuild, as a means of testing.
This diff was not scripted. Should be zero rebuilds.
<details>
<summary>
Alternatives
</summary>
Alternatively I could have use this pattern:
```nix
postInstall = lib.optionalString (stdenv.hostPlatform.emulatorAvailable buildPackages) (
let
emulator = stdenv.hostPlatform.emulator buildPackages;
in
''
installShellCompletion --cmd foobar \
--bash <(${emulator} $out/bin/foobar completion bash) \
--fish <(${emulator} $out/bin/foobar completion fish) \
--zsh <(${emulator} $out/bin/foobar completion zsh)
''
);
```
but that would cause rebuilds and will also require testing.
---
An other alternative is to use the binary from the corresponding package in `buildPackages`.
This however would also cause rebuilds and will also require testing.
</details>
|
||
|---|---|---|
| .. | ||
| package.nix | ||