Files
nixpkgs/pkgs/by-name/up/uplosi/package.nix
Peder Bergebakken Sundt 8bffdd4ccf 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>
2025-09-12 14:08:39 +02:00

53 lines
1.3 KiB
Nix

{
lib,
stdenv,
fetchFromGitHub,
buildGoModule,
installShellFiles,
nix-update-script,
}:
buildGoModule (finalAttrs: {
pname = "uplosi";
version = "0.4.0";
src = fetchFromGitHub {
owner = "edgelesssys";
repo = "uplosi";
tag = "v${finalAttrs.version}";
hash = "sha256-5I916T70sH4UAq5EGRjR7lnRBbPqMJIxaXwUCJQ4DcM=";
};
vendorHash = "sha256-2lJmPNLpI1ksFb0EtcjPjyTy7eX1DKeX0F80k9FtGno=";
env.CGO_ENABLED = "0";
ldflags = [
"-s"
"-X main.version=${finalAttrs.version}"
];
nativeBuildInputs = [ installShellFiles ];
postInstall = lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
installShellCompletion --cmd uplosi \
--bash <($out/bin/uplosi completion bash) \
--fish <($out/bin/uplosi completion fish) \
--zsh <($out/bin/uplosi completion zsh)
'';
passthru.updateScript = nix-update-script { };
meta = {
description = "Upload OS images to cloud provider";
homepage = "https://github.com/edgelesssys/uplosi";
changelog = "https://github.com/edgelesssys/uplosi/releases/tag/v${finalAttrs.version}";
license = lib.licenses.asl20;
mainProgram = "uplosi";
maintainers = with lib.maintainers; [
katexochen
malt3
];
platforms = lib.platforms.unix;
};
})