acr-cli: init at 0.14 (#359508)
[NixPkgs.git] / pkgs / by-name / k3 / k3d / package.nix
blob37c256b714b076bbe1855799ac3cf537614efe6c
1 { lib
2 , buildGoModule
3 , fetchFromGitHub
4 , installShellFiles
5 , k3sVersion ? null
6 }:
8 let
9   hasVPrefix = ver: (builtins.elemAt (lib.stringToCharacters ver) 0) == "v";
10   k3sVersionSet =
11     if k3sVersion != null then
12       if hasVPrefix k3sVersion then throw "k3sVersion should not have a v prefix" else true
13     else
14       false;
16 buildGoModule rec {
17   pname = "k3d";
18   version = "5.7.4";
20   src = fetchFromGitHub {
21     owner = "k3d-io";
22     repo = "k3d";
23     rev = "refs/tags/v${version}";
24     hash = "sha256-z+7yeX0ea/6+4aWbA5NYW/HzvVcJiSkewOvo+oXp9bE=";
25   };
27   vendorHash = "sha256-lFmIRtkUiohva2Vtg4AqHaB5McVOWW5+SFShkNqYVZ8=";
28   deleteVendor = true;
30   nativeBuildInputs = [ installShellFiles ];
32   excludedPackages = [ "tools" "docgen" ];
34   ldflags =
35     let t = "github.com/k3d-io/k3d/v${lib.versions.major version}/version"; in
36     [ "-s" "-w" "-X ${t}.Version=v${version}" ] ++ lib.optionals k3sVersionSet [ "-X ${t}.K3sVersion=v${k3sVersion}" ];
38   preCheck = ''
39     # skip test that uses networking
40     substituteInPlace version/version_test.go \
41       --replace "TestGetK3sVersion" "SkipGetK3sVersion"
42   '';
44   postInstall = ''
45     installShellCompletion --cmd k3d \
46       --bash <($out/bin/k3d completion bash) \
47       --fish <($out/bin/k3d completion fish) \
48       --zsh <($out/bin/k3d completion zsh)
49   '';
51   doInstallCheck = true;
52   installCheckPhase = ''
53     runHook preInstallCheck
54     $out/bin/k3d --help
55     $out/bin/k3d --version | grep -e "k3d version v${version}" ${lib.optionalString k3sVersionSet "-e \"k3s version v${k3sVersion}\""}
56     runHook postInstallCheck
57   '';
59   env.GOWORK = "off";
61   meta = with lib; {
62     homepage = "https://github.com/k3d-io/k3d/";
63     changelog = "https://github.com/k3d-io/k3d/blob/v${version}/CHANGELOG.md";
64     description = "Helper to run k3s (Lightweight Kubernetes. 5 less than k8s) in a docker container";
65     mainProgram = "k3d";
66     longDescription = ''
67       k3s is the lightweight Kubernetes distribution by Rancher: rancher/k3s
69       k3d creates containerized k3s clusters. This means, that you can spin up a
70       multi-node k3s cluster on a single machine using docker.
71     '';
72     license = licenses.mit;
73     maintainers = with maintainers; [ kuznero jlesquembre ngerstle jk ricochet ];
74     platforms = platforms.linux ++ platforms.darwin;
75   };