nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildGoModule,
4 fetchFromGitHub,
5 makeWrapper,
6 installShellFiles,
7 buildkit,
8 cni-plugins,
9 writableTmpDirAsHomeHook,
10 versionCheckHook,
11 extraPackages ? [ ],
12 nix-update-script,
13}:
14
15buildGoModule (finalAttrs: {
16 pname = "nerdctl";
17 version = "2.2.1";
18
19 src = fetchFromGitHub {
20 owner = "containerd";
21 repo = "nerdctl";
22 tag = "v${finalAttrs.version}";
23 hash = "sha256-KD7wXU3RSWJWLSOd7ZFEAfETezb/5ijWPyxXMjIeX6E=";
24 };
25
26 vendorHash = "sha256-vq4NpKS8JvsOGK25fksjsqdNS6H/B1VPqTYwqYv2blc=";
27
28 nativeBuildInputs = [
29 makeWrapper
30 installShellFiles
31 writableTmpDirAsHomeHook
32 ];
33
34 ldflags =
35 let
36 t = "github.com/containerd/nerdctl/v${lib.versions.major finalAttrs.version}/pkg/version";
37 in
38 [
39 "-s"
40 "-w"
41 "-X ${t}.Version=v${finalAttrs.version}"
42 "-X ${t}.Revision=<unknown>"
43 ];
44
45 # testing framework which we don't need and can't be build as it is an extra go application
46 excludedPackages = [ "mod/tigron" ];
47
48 # Many checks require a containerd socket and running nerdctl after it's built
49 doCheck = false;
50
51 postInstall = ''
52 wrapProgram $out/bin/nerdctl \
53 --prefix PATH : "${lib.makeBinPath ([ buildkit ] ++ extraPackages)}" \
54 --prefix CNI_PATH : "${cni-plugins}/bin"
55
56 installShellCompletion --cmd nerdctl \
57 --bash <($out/bin/nerdctl completion bash) \
58 --fish <($out/bin/nerdctl completion fish) \
59 --zsh <($out/bin/nerdctl completion zsh)
60 '';
61
62 doInstallCheck = true;
63 nativeInstallCheckInputs = [
64 writableTmpDirAsHomeHook
65 versionCheckHook
66 ];
67 versionCheckKeepEnvironment = [ "HOME" ];
68
69 passthru = {
70 updateScript = nix-update-script {
71 extraArgs = [ "--version-regex=^v([0-9.]+)$" ];
72 };
73 };
74
75 meta = {
76 homepage = "https://github.com/containerd/nerdctl/";
77 changelog = "https://github.com/containerd/nerdctl/releases/tag/v${finalAttrs.version}";
78 description = "Docker-compatible CLI for containerd";
79 mainProgram = "nerdctl";
80 license = lib.licenses.asl20;
81 maintainers = with lib.maintainers; [
82 developer-guy
83 jk
84 ];
85 platforms = lib.platforms.linux;
86 };
87})