Skip to content

Commit

Permalink
stackit-cli: init at 0.1.0-apt-prerelease.3
Browse files Browse the repository at this point in the history
  • Loading branch information
DerRockWolf committed Mar 20, 2024
1 parent 9a0bb93 commit b983f80
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions pkgs/by-name/st/stackit-cli/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{ lib
, buildGoModule
, fetchFromGitHub
, installShellFiles
, makeWrapper
, less
, xdg-utils
, testers
, runCommand
, stackit-cli
}:

buildGoModule rec {
pname = "stackit-cli";
version = "0.1.0-apt-prerelease.3";

src = fetchFromGitHub {
owner = "stackitcloud";
repo = "stackit-cli";
rev = "v${version}";
hash = "sha256-WpIGWUhqjNjOnaK5pTKYgXjCasbfzSrjcnqcMTM9sBo=";
};

vendorHash = "sha256-nhOhS8fB48gOnlsUPlUprdp3iNeDO9AMFymCa7zsVSY=";

subPackages = [ "." ];

CGO_ENABLED = 0;

ldflags = [
"-s"
"-w"
"-X main.version=${version}"
];

nativeBuildInputs = [ installShellFiles makeWrapper ];

preCheck = ''
export HOME=$TMPDIR # needed because the binary always creates a dir & config file
'';

postInstall = ''
export HOME=$TMPDIR # needed because the binary always creates a dir & config file
mv $out/bin/{${pname},stackit} # rename the binary
installShellCompletion --cmd stackit --bash <($out/bin/stackit completion bash)
installShellCompletion --cmd stackit --zsh <($out/bin/stackit completion zsh)
installShellCompletion --cmd stackit --fish <($out/bin/stackit completion fish)
# Use this instead, once https://github.com/stackitcloud/stackit-cli/issues/153 is fixed:
# installShellCompletion --cmd stackit \
# --bash <($out/bin/stackit completion bash) \
# --zsh <($out/bin/stackit completion zsh) \
# --fish <($out/bin/stackit completion fish)
'';

postFixup = ''
wrapProgram $out/bin/stackit \
--prefix PATH : ${lib.makeBinPath [ less xdg-utils ]}
'';

nativeCheckInputs = [ less ];

passthru.tests = {
version = testers.testVersion {
package = stackit-cli;
command = "HOME=$TMPDIR stackit --version";
};
# Ensure that all 3 completion scripts exist AND have content (should be kept for regression testing)
completion = runCommand "${pname}-test" {} ''
[ $(find ${stackit-cli}/share -not -empty -type f | wc -l) -eq 3 ]
touch $out
'';
};

meta = with lib; {
description = "A CLI to manage STACKIT cloud services";
homepage = "https://github.com/stackitcloud/stackit-cli";
changelog = "https://github.com/stackitcloud/stackit-cli/releases/tag/v${version}";
license = licenses.asl20;
maintainers = with maintainers; [ DerRockWolf ];
platforms = platforms.linux ++ platforms.darwin;
mainProgram = "stackit";
};
}

0 comments on commit b983f80

Please sign in to comment.