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>
74 lines
1.8 KiB
Nix
74 lines
1.8 KiB
Nix
{
|
|
lib,
|
|
stdenv,
|
|
buildGoModule,
|
|
fetchFromGitHub,
|
|
installShellFiles,
|
|
kustomize,
|
|
testers,
|
|
}:
|
|
|
|
buildGoModule (finalAttrs: {
|
|
pname = "kustomize";
|
|
version = "5.7.1";
|
|
|
|
ldflags =
|
|
let
|
|
t = "sigs.k8s.io/kustomize/api/provenance";
|
|
in
|
|
[
|
|
"-s"
|
|
"-X ${t}.version=v${finalAttrs.version}" # add 'v' prefix to match official releases
|
|
"-X ${t}.gitCommit=${finalAttrs.src.rev}"
|
|
];
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "kubernetes-sigs";
|
|
repo = "kustomize";
|
|
rev = "kustomize/v${finalAttrs.version}";
|
|
hash = "sha256-eLj9OQlHZph/rI3om6S5/0sYxjgYloUWag2mS0hEpCE=";
|
|
};
|
|
|
|
# avoid finding test and development commands
|
|
modRoot = "kustomize";
|
|
proxyVendor = true;
|
|
vendorHash = "sha256-OodR5WXEEn4ZlVRTsH2uSmuJuP+6PYRLvTEZCenx4XU=";
|
|
|
|
nativeBuildInputs = [ installShellFiles ];
|
|
|
|
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
|
|
installShellCompletion --cmd kustomize \
|
|
--bash <($out/bin/kustomize completion bash) \
|
|
--fish <($out/bin/kustomize completion fish) \
|
|
--zsh <($out/bin/kustomize completion zsh)
|
|
'';
|
|
|
|
passthru.tests = {
|
|
versionCheck = testers.testVersion {
|
|
command = "${finalAttrs.meta.mainProgram} version";
|
|
version = "v${finalAttrs.version}";
|
|
package = kustomize;
|
|
};
|
|
};
|
|
|
|
meta = {
|
|
description = "Customization of kubernetes YAML configurations";
|
|
mainProgram = "kustomize";
|
|
longDescription = ''
|
|
kustomize lets you customize raw, template-free YAML files for
|
|
multiple purposes, leaving the original YAML untouched and usable
|
|
as is.
|
|
'';
|
|
homepage = "https://github.com/kubernetes-sigs/kustomize";
|
|
license = lib.licenses.asl20;
|
|
maintainers = with lib.maintainers; [
|
|
carlosdagos
|
|
vdemeester
|
|
periklis
|
|
zaninime
|
|
Chili-Man
|
|
saschagrunert
|
|
];
|
|
};
|
|
})
|