Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 buildGoModule,
3 fetchFromGitHub,
4 lib,
5 stdenvNoCC,
6 installShellFiles,
7 versionCheckHook,
8 nix-update-script,
9 ...
10}:
11
12buildGoModule (finalAttrs: {
13 pname = "tcld";
14 version = "0.41.0";
15 src = fetchFromGitHub {
16 owner = "temporalio";
17 repo = "tcld";
18 rev = "refs/tags/v${finalAttrs.version}";
19 hash = "sha256-Jnm6l9Jj1mi9esDS6teKTEMhq7V1QD/dTl3qFhKsW4o=";
20 # Populate values from the git repository; by doing this in 'postFetch' we
21 # can delete '.git' afterwards and the 'src' should stay reproducible.
22 leaveDotGit = true;
23 postFetch = ''
24 cd "$out"
25 # Replicate 'COMMIT' and 'DATE' variables from upstream's Makefile.
26 git rev-parse --short=12 HEAD > $out/COMMIT
27 git log -1 --format=%cd --date=iso-strict > $out/SOURCE_DATE_EPOCH
28 find "$out" -name .git -exec rm -rf '{}' '+'
29 '';
30 };
31
32 vendorHash = "sha256-GOko8nboj7eN4W84dqP3yLD6jK7GA0bANV0Tj+1GpgY=";
33
34 subPackages = [ "cmd/tcld" ];
35 ldflags = [
36 "-s"
37 "-w"
38 "-X=github.com/temporalio/tcld/app.version=${finalAttrs.version}"
39 ];
40
41 # ldflags based on metadata from git.
42 preBuild = ''
43 ldflags+=" -X=github.com/temporalio/tcld/app.date=$(cat SOURCE_DATE_EPOCH)"
44 ldflags+=" -X=github.com/temporalio/tcld/app.commit=$(cat COMMIT)"
45 '';
46
47 # FIXME: Remove after https://github.com/temporalio/tcld/pull/447 lands.
48 patches = [ ./compgen.patch ];
49
50 # NOTE: Some tests appear to require (local only?) network access, which
51 # doesn't work in the sandbox.
52 __darwinAllowLocalNetworking = true;
53
54 nativeBuildInputs = [ installShellFiles ];
55 postInstall = lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) ''
56 installShellCompletion --cmd tcld --bash ${./bash_autocomplete}
57 installShellCompletion --cmd tcld --zsh ${./zsh_autocomplete}
58 '';
59
60 nativeInstallCheckInputs = [ versionCheckHook ];
61 doInstallCheck = true;
62 versionCheckProgram = "${placeholder "out"}/bin/${finalAttrs.meta.mainProgram}";
63 versionCheckProgramArg = "version";
64
65 passthru.updateScript = nix-update-script { };
66
67 meta = {
68 description = "Temporal cloud cli";
69 homepage = "https://www.github.com/temporalio/tcld";
70 changelog = "https://github.com/temporalio/tcld/releases/tag/v${finalAttrs.version}";
71 license = lib.licenses.mit;
72 teams = [ lib.teams.mercury ];
73 mainProgram = "tcld";
74 };
75})