-
Notifications
You must be signed in to change notification settings - Fork 81
/
flake.nix
151 lines (132 loc) · 5.28 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{
description = "Nix package for centrifuge-chain";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-21.11;
flake-utils = {
url = github:numtide/flake-utils;
inputs.nixpkgs.follows = "nixpkgs";
};
gitignore = {
url = github:hercules-ci/gitignore.nix;
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = github:nix-community/fenix;
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs :
inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
cargoTOML = builtins.fromTOML (builtins.readFile ./Cargo.toml);
rustToolChainTOML = builtins.fromTOML (builtins.readFile ./rust-toolchain.toml);
name = cargoTOML.package.name;
# This is the program version.
version = cargoTOML.package.version;
# This selects a nightly Rust version, based on the date.
nightly-date = pkgs.lib.strings.removePrefix "nightly-" rustToolChainTOML.toolchain.channel;
# This is the hash of the Rust toolchain at nightly-date, required for reproducibility.
nightly-sha256 = "sha256-hEf6+Lr/Pi7Mn6ESUrNYw9Wn8vKOpicKG/Y/3p5WQlo=";
# This is the git short commit of the current version of the program.
shortCommit = builtins.substring 0 7 (inputs.self.rev or "dirty");
# This instantiates a new Rust version based on nightly-date.
nightlyRustPlatform = pkgs.makeRustPlatform {
inherit
(inputs.fenix.packages.${system}.toolchainOf {
channel = "nightly";
date = nightly-date;
sha256 = nightly-sha256;
})
cargo rustc;
};
# This is a mock git program, which just returns the commit-substr value.
# It is called when the build process calls git. Instead of the real git,
# it will find this one.
git-mock =
pkgs.writeShellScriptBin "git" ''
echo ${shortCommit}
'';
# srcFilter is used to keep out of the build non-source files,
# so that we only trigger a rebuild when necessary.
srcFilter = src:
let
isGitIgnored = inputs.gitignore.lib.gitignoreFilter src;
ignoreList = [
".dockerignore"
".envrc"
".github"
".travis.yml"
"CODE_OF_CONDUCT.md"
"README.md"
"ci"
"cloudbuild.yaml"
"codecov.yml"
"docker-compose.yml"
"rustfmt.toml"
];
in
path: type:
isGitIgnored path type
&& builtins.all (name: builtins.baseNameOf path != name) ignoreList;
in
rec {
defaultPackage = nightlyRustPlatform.buildRustPackage {
pname = name;
inherit version;
inherit shortCommit;
# This applies the srcFilter function to the current directory, so
# we don't include unnecessary files in the package.
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = srcFilter ./.;
name = "${name}-source";
};
# This is a hash of all the Cargo dependencies, for reproducibility.
cargoSha256 = "sha256-/idodSvHfn0LdkdMt1pznh72XzAZSjGMzJqVseyZ+JU=";
nativeBuildInputs = with pkgs; [ clang git-mock pkg-config ];
buildInputs = with pkgs; [ openssl ] ++ (
lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Security
darwin.apple_sdk.frameworks.SystemConfiguration
]
);
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
PROTOC = "${pkgs.protobuf}/bin/protoc";
SKIP_WASM_BUILD = 1;
doCheck = false;
};
packages.fastRuntime = defaultPackage.overrideAttrs (base: {
buildFeatures = [ "fast-runtime" ];
});
# Docker image package doesn't work on Darwin Archs
packages.dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "centrifugeio/${name}";
tag = "${version}-${shortCommit}-nix-do-not-use"; # todo remove suffix once verified
# This uses the date of the last commit as the image creation date.
created = builtins.substring 0 8 inputs.self.lastModifiedDate;
contents = [
pkgs.busybox
inputs.self.defaultPackage.${system}
];
config = {
ExposedPorts = {
"30333/tcp" = { };
"9933/tcp" = { };
"9944/tcp" = { };
};
Volumes = {
"/data" = { };
};
Entrypoint = [ "centrifuge-chain" ];
};
};
packages.dockerImageFastRuntime = packages.dockerImage.overrideAttrs (base: {
tag = "test-${version}-${shortCommit}-nix-do-not-use"; # todo remove suffix once verified
contents = [
pkgs.busybox
packages.fastRuntime
];
});
});
}