forked from crypto-org-chain/chain-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
85 lines (83 loc) · 2.21 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ lib
, stdenv
, buildGoApplication
, nix-gitignore
, go_1_18
, rocksdb ? null
, network ? "mainnet" # mainnet|testnet
, rev ? "dirty"
, ledger_zemu ? false
}:
let
inherit (lib) concatStringsSep;
src_regexes = [
"^x$"
"^x/.*"
"^app$"
"^app/.*"
"^config$"
"^config/.*"
"^cmd$"
"^cmd/.*"
"^proto$"
"^proto/.*"
"^test$"
"^test/.*"
"^go.mod$"
"^go.sum$"
"^third_party$"
"^third_party/cosmos-sdk$"
"^third_party/cosmos-sdk/.*"
"^gomod2nix.toml$"
];
in
buildGoApplication rec {
pname = "chain-maind";
version = "4.0.0";
go = go_1_18;
src = lib.cleanSourceWith {
name = "src";
src = lib.sourceByRegex ./. src_regexes;
};
modules = ./gomod2nix.toml;
subPackages = [ "cmd/chain-maind" ];
buildInputs = lib.lists.optional (rocksdb != null) rocksdb;
CGO_ENABLED = "1";
outputs = [
"out"
"instrumented"
];
tags = [
"cgo"
"ledger"
"!test_ledger_mock"
"!ledger_mock"
(if ledger_zemu then "ledger_zemu" else "!ledger_zemu")
network
] ++ lib.lists.optionals (rocksdb != null) [ "rocksdb" "rocksdb_build" ];
ldflags = ''
-X github.com/cosmos/cosmos-sdk/version.Name=crypto-org-chain
-X github.com/cosmos/cosmos-sdk/version.AppName=${pname}
-X github.com/cosmos/cosmos-sdk/version.Version=${version}
-X github.com/cosmos/cosmos-sdk/version.Commit=${rev}
-X github.com/cosmos/cosmos-sdk/version.BuildTags=${concatStringsSep "," tags}
'';
instrumentedBinary = "chain-maind-inst";
postBuild = ''
echo "Build instrumented binary"
go test ./cmd/chain-maind ''${tags:+-tags=${concatStringsSep "," tags}}",testbincover" ''${ldflags:+-ldflags="$ldflags"} "''${buildFlagsArray[@]}" -coverpkg=./...,github.com/cosmos/cosmos-sdk/x/... -c -o ${instrumentedBinary}
'';
preInstall = ''
mkdir -p $instrumented/bin
mv ./${instrumentedBinary} $instrumented/bin/
'';
preFixup = ''
find $instrumented/bin/ -type f 2>/dev/null | xargs -r remove-references-to -t ${go} || true
'';
meta = with lib; {
description = "Official implementation of the Crypto.org blockchain protocol";
homepage = "https://crypto.org/";
license = licenses.asl20;
mainProgram = "chain-maind";
};
}