From 551cee25b6751897fe34975ca60ac6636601ed9a Mon Sep 17 00:00:00 2001 From: Benjamin Staffin Date: Mon, 26 Nov 2018 20:35:48 -0500 Subject: [PATCH] stern: build shell completion scripts even when cross-compiling (#51075) Moments after merging #49668 I realized that this is not hard to do correctly, so here it is now. --- .../networking/cluster/stern/default.nix | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pkgs/applications/networking/cluster/stern/default.nix b/pkgs/applications/networking/cluster/stern/default.nix index 75a88d14e4c8..bb0f3229ea5e 100644 --- a/pkgs/applications/networking/cluster/stern/default.nix +++ b/pkgs/applications/networking/cluster/stern/default.nix @@ -1,4 +1,6 @@ -{ stdenv, lib, buildGoPackage, fetchFromGitHub }: +{ stdenv, lib, buildPackages, buildGoPackage, fetchFromGitHub }: + +let isCrossBuild = stdenv.hostPlatform != stdenv.buildPlatform; in buildGoPackage rec { name = "stern-${version}"; @@ -15,14 +17,14 @@ buildGoPackage rec { goDeps = ./deps.nix; - # Only build shell completion if we're _not_ cross compiling, - # because it requires executing the compiled stern binary. - postInstall = lib.optionalString (stdenv.buildPlatform == stdenv.hostPlatform) '' - mkdir -p $bin/share/bash-completion/completions - $bin/bin/stern --completion bash > $bin/share/bash-completion/completions/stern - mkdir -p $bin/share/zsh/site-functions - $bin/bin/stern --completion zsh > $bin/share/zsh/site-functions/_stern - ''; + postInstall = + let stern = if isCrossBuild then buildPackages.stern else "$bin"; in + '' + mkdir -p $bin/share/bash-completion/completions + ${stern}/bin/stern --completion bash > $bin/share/bash-completion/completions/stern + mkdir -p $bin/share/zsh/site-functions + ${stern}/bin/stern --completion zsh > $bin/share/zsh/site-functions/_stern + ''; meta = with lib; { description = "Multi pod and container log tailing for Kubernetes";