-
Notifications
You must be signed in to change notification settings - Fork 350
/
default.nix
93 lines (92 loc) · 2.69 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
86
87
88
89
90
91
92
93
{ lib
, stdenv
, buildGoApplication
, nix-gitignore
, writeShellScript
, buildPackages
, coverage ? false # https://tip.golang.org/doc/go1.20#cover
, gomod2nix
, rocksdb ? null
, network ? "mainnet" # mainnet|testnet
, rev ? "dirty"
, ledger_zemu ? false
, static ? stdenv.hostPlatform.isStatic
, nativeByteOrder ? true # nativeByteOrder mode will panic on big endian machines
}:
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.2.10";
go = buildPackages.go_1_20;
src = lib.cleanSourceWith {
name = "src";
src = lib.sourceByRegex ./. src_regexes;
};
modules = ./gomod2nix.toml;
subPackages = [ "cmd/chain-maind" ];
buildFlags = lib.optionalString coverage "-cover";
buildInputs = lib.lists.optional (rocksdb != null) rocksdb;
CGO_ENABLED = "1";
CGO_LDFLAGS =
if static then "-lrocksdb -pthread -lstdc++ -ldl -lzstd -lsnappy -llz4 -lbz2 -lz"
else if stdenv.hostPlatform.isWindows then "-lrocksdb-shared"
else "-lrocksdb -pthread -lstdc++ -ldl";
tags = [
"cgo"
"ledger"
"!test_ledger_mock"
"!ledger_mock"
(if ledger_zemu then "ledger_zemu" else "!ledger_zemu")
network
] ++ lib.optionals (rocksdb != null) [ "rocksdb" "grocksdb_no_link" ]
++ lib.optionals nativeByteOrder [ "nativebyteorder" ];
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}
'';
postFixup = lib.optionalString stdenv.isDarwin ''
${stdenv.cc.targetPrefix}install_name_tool -change "@rpath/librocksdb.8.dylib" "${rocksdb}/lib/librocksdb.dylib" $out/bin/chain-maind
'';
passthru = {
# update script use the same golang version as the project
updateScript =
let helper = gomod2nix.override { inherit go; };
in
writeShellScript "${pname}-updater" ''
exec ${helper}/bin/gomod2nix
'';
};
doCheck = false;
meta = with lib; {
description = "Official implementation of the Crypto.org blockchain protocol";
homepage = "https://crypto.org/";
license = licenses.asl20;
mainProgram = "chain-maind" + stdenv.hostPlatform.extensions.executable;
platforms = platforms.all;
};
}