nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildGoModule,
4 fetchFromGitHub,
5 versionCheckHook,
6 nix-update-script,
7}:
8
9buildGoModule (finalAttrs: {
10 pname = "betteralign";
11 version = "0.8.3";
12
13 src = fetchFromGitHub {
14 owner = "dkorunic";
15 repo = "betteralign";
16 tag = "v${finalAttrs.version}";
17 hash = "sha256-1YAuIdSLibCmiWNRMjVJJHv64Rx8jzO5AyJg+I05Vu0=";
18
19 # Trick for getting accurate commit, source date and timestamp for ldflags
20 # Required by upstream https://github.com/dkorunic/betteralign/blob/346baa9c9dd024bfe55302c9d7d0ca46b2734c1c/.goreleaser.yml
21 leaveDotGit = true;
22 postFetch = ''
23 cd "$out"
24 git rev-parse HEAD > $out/COMMIT
25 git log -1 --pretty=%cd --date=format:'%Y-%m-%dT%H:%M:%SZ' > $out/SOURCE_DATE
26 git log -1 --pretty=%cd --date=format:'%s' > $out/SOURCE_TIMESTAMP
27 find "$out" -name .git -print0 | xargs -0 rm -rf
28 '';
29 };
30
31 vendorHash = "sha256-9jhlshLzS+fNri8eax8SrX1X0KqzQ4clgSyVgXqcx04=";
32
33 env.CGO_ENABLED = 0;
34
35 ldflags = [
36 "-s -w"
37 "-X main.Version=${finalAttrs.version}"
38 ];
39
40 preBuild = ''
41 ldflags+=" -X main.Commit=$(cat COMMIT)"
42 ldflags+=" -X main.Date=$(cat SOURCE_DATE)"
43 ldflags+=" -X main.Timestamp=$(cat SOURCE_TIMESTAMP)"
44 '';
45
46 nativeInstallCheckInputs = [ versionCheckHook ];
47 versionCheckProgramArg = "-V";
48 doInstallCheck = true;
49
50 passthru.updateScript = nix-update-script { };
51
52 meta = {
53 description = "Make your Go programs use less memory (maybe)";
54 longDescription = ''
55 betteralign is a tool to detect structs that would use less
56 memory if their fields were sorted and optionally sort such fields.
57 '';
58 homepage = "https://github.com/dkorunic/betteralign";
59 changelog = "https://github.com/dkorunic/betteralign/releases/tag/v${finalAttrs.version}";
60 license = lib.licenses.bsd3;
61 mainProgram = "betteralign";
62 maintainers = with lib.maintainers; [ cterence ];
63 };
64})