forked from crypto-org-chain/chain-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
114 lines (113 loc) · 3.5 KB
/
flake.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
nix-bundle-exe = {
url = "github:3noch/nix-bundle-exe";
flake = false;
};
gomod2nix = {
url = "github:yihuang/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
rocksdb-src = {
url = "github:facebook/rocksdb/v6.29.5";
flake = false;
};
};
outputs = { self, nixpkgs, nix-bundle-exe, gomod2nix, flake-utils, rocksdb-src }:
let
rev = self.shortRev or "dirty";
mkApp = drv: {
type = "app";
program = "${drv}/bin/${drv.meta.mainProgram}";
};
in
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
gomod2nix.overlays.default
self.overlay
];
config = { };
};
in
rec {
packages = pkgs.chain-main-matrix;
apps = {
chain-maind = mkApp packages.chain-maind;
chain-maind-testnet = mkApp packages.chain-maind-testnet;
};
defaultPackage = packages.chain-maind;
defaultApp = apps.chain-maind;
devShells = {
chain-maind = pkgs.mkShell {
buildInputs = with pkgs; [
go_1_18
rocksdb
libwasmvm
];
};
};
devShell = devShells.chain-maind;
}
)
) // {
overlay = final: prev: {
bundle-exe = import nix-bundle-exe { pkgs = final; };
# make-tarball don't follow symbolic links to avoid duplicate file, the bundle should have no external references.
# reset the ownership and permissions to make the extract result more normal.
make-tarball = drv: with final; runCommand drv.name { } ''
"${gnutar}/bin/tar" cfv - -C ${drv} \
--owner=0 --group=0 --mode=u+rw,uga+r --hard-dereference . \
| "${gzip}/bin/gzip" -9 > $out
'';
rocksdb = (prev.rocksdb.overrideAttrs (old: rec {
pname = "rocksdb";
version = "6.29.5";
src = rocksdb-src;
})).override { enableJemalloc = true; };
} // (with final;
let
matrix = lib.cartesianProductOfSets {
network = [ "mainnet" "testnet" ];
pkgtype = [
"nix" # normal nix package
"bundle" # relocatable bundled package
"tarball" # tarball of the bundle, for distribution and checksum
];
};
binaries = builtins.listToAttrs (builtins.map
({ network, pkgtype }: {
name = builtins.concatStringsSep "-" (
[ "chain-maind" ] ++
lib.optional (network != "mainnet") network ++
lib.optional (pkgtype != "nix") pkgtype
);
value =
let
chain-maind = callPackage ./. {
inherit rev network;
};
bundle = bundle-exe chain-maind;
in
if pkgtype == "bundle" then
bundle
else if pkgtype == "tarball" then
make-tarball bundle
else
chain-maind;
})
matrix
);
in
{
chain-main-matrix = binaries;
}
);
};
}