Commit 8bffdd4c authored by Peder Bergebakken Sundt's avatar Peder Bergebakken Sundt
Browse files

treewide: gate command execution for `installShellCompletion` behind...

treewide: gate command execution for `installShellCompletion` behind `buildPlatform.canExecute hostPlatform`

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>
parent acbc6a95
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  buildGoModule,
  fetchFromGitHub,
  installShellFiles,
@@ -45,7 +46,7 @@ let

      doCheck = false;

      postInstall = ''
      postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
        installShellCompletion --cmd kops \
          --bash <($GOPATH/bin/kops completion bash) \
          --fish <($GOPATH/bin/kops completion fish) \
+9 −6
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchFromGitHub,
  buildGoModule,
  coredns,
@@ -40,12 +41,14 @@ buildGoModule rec {
  subPackages = map (p: "app/" + p) components;

  postInstall =
    lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) (
      lib.concatMapStringsSep "\n" (p: ''
        installShellCompletion --cmd ${p} \
          --bash <($out/bin/${p} completion bash) \
          --fish <($out/bin/${p} completion fish) \
          --zsh <($out/bin/${p} completion zsh)
      '') components
    )
    + lib.optionalString isFull ''
      ln -sLf ${coredns}/bin/coredns $out/bin
    '';
+3 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchFromGitHub,
  buildGoModule,
  installShellFiles,
@@ -51,6 +52,8 @@ buildGoModule rec {

  postInstall = ''
    mv $out/bin/cli $out/bin/linkerd
  ''
  + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    installShellCompletion --cmd linkerd \
      --bash <($out/bin/linkerd completion bash) \
      --zsh <($out/bin/linkerd completion zsh) \
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ stdenv.mkDerivation {
    runHook postInstall
  '';

  postInstall = ''
  postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    HOME=$TMPDIR
    installShellCompletion --cmd ${mainProgram} \
      --bash <($out/bin/${mainProgram} completion bash) \
+2 −1
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  buildGoModule,
  fetchFromGitHub,
  installShellFiles,
@@ -27,7 +28,7 @@ buildGoModule rec {
    "-w"
  ];

  postInstall = ''
  postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
    installShellCompletion --cmd abbreviate \
      --bash <($out/bin/abbreviate completion bash) \
      --fish <($out/bin/abbreviate completion fish) \
Loading