-
Notifications
You must be signed in to change notification settings - Fork 56
/
flake.nix
279 lines (257 loc) · 9.85 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
{
description = ''
A Nix flake for the Fuel Labs ecosystem.
'';
inputs = {
nixpkgs = {
url = "github:NixOS/nixpkgs/nixos-unstable";
};
rust-overlay = {
url = "github:oxalica/rust-overlay/master";
inputs.nixpkgs.follows = "nixpkgs";
};
sway-vim-src = {
url = "github:fuellabs/sway.vim";
flake = false;
};
utils = {
url = "github:numtide/flake-utils";
};
};
outputs = inputs: let
utils.supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"i686-linux"
"x86_64-darwin"
"aarch64-darwin"
];
utils.eachSupportedSystem =
inputs.utils.lib.eachSystem utils.supportedSystems;
# Collect the package manifests and sort them into published, nightly,
# latest and default sets.
mkManifests = pkgs: let
# Load the manually defined filters and patches.
filters = import ./filters.nix {inherit pkgs;};
patches = import ./patches.nix {inherit pkgs;};
mstones = import ./milestones.nix;
# Returns true if the given manifest passes all our filters.
filter = m: pkgs.lib.all (f: f m) filters;
# Apply all `patches` whose conditions are met by the given manifest.
patch = let
filtered = m: pkgs.lib.filter (p: p.condition m) patches;
apply = m: p: pkgs.lib.recursiveUpdate m (p.patch m);
in
m: pkgs.lib.foldl apply m (filtered m);
# Load a manifest file given its filename and construct the attributes.
manifest = filename: let
fileattrs = import (./manifests + "/${filename}");
in {
inherit (fileattrs) pname version date;
src = pkgs.fetchgit {
inherit (fileattrs) url rev sha256;
};
};
in rec {
# Read the manifest files.
filenames = builtins.attrNames (builtins.readDir ./manifests);
# Filter and patch the published package manifests.
published = rec {
fnames = builtins.filter (n: !(pkgs.lib.hasInfix "nightly" n)) filenames;
all = map manifest fnames;
filtered = ms: builtins.filter filter ms;
patched = ms: map patch ms;
prepared = patched (filtered all);
};
# Filter and patch the nightly package manifests.
nightly = rec {
fnames = builtins.filter (n: pkgs.lib.hasInfix "nightly" n) filenames;
all = map manifest fnames;
filtered = ms: builtins.filter filter ms;
patched = ms: map patch ms;
prepared = patched (filtered all);
};
# Find the latest published and nightly version for each package.
latest = let
update = m: acc:
acc
// {
"${m.pname}" =
if builtins.hasAttr m.pname acc && pkgs.lib.versionAtLeast acc."${m.pname}".version m.version && acc."${m.pname}".date >= m.date
then acc."${m.pname}"
else m;
};
mapPublished = name: v: pkgs.lib.nameValuePair (name + "-latest") v;
mapNightly = name: v: pkgs.lib.nameValuePair (name + "-nightly") v;
foldPublished = pkgs.lib.foldr update {} published.prepared;
foldNightly = pkgs.lib.foldr update {} nightly.prepared;
in {
published = pkgs.lib.mapAttrs' mapPublished foldPublished;
nightly = pkgs.lib.mapAttrs' mapNightly foldNightly;
};
# Construct the milestone package lists, e.g. `{ beta-4 = [...]; beta-5 = [...]; }`.
milestones = let
filterPkg = revs: m: builtins.any (rev: rev == m.src.rev) (builtins.attrValues revs);
filterPublished = revs: builtins.filter (filterPkg revs) published.prepared;
mapPkg = mname: m: m // {pname = "${m.pname}" + "-" + "${mname}";};
milestonePkgs = name: revs: map (mapPkg name) (filterPublished revs);
mapMilestone = name: revs: pkgs.lib.nameValuePair name (milestonePkgs name revs);
in
pkgs.lib.mapAttrs' mapMilestone mstones;
# Construct the default packages as aliases of the latest versions.
defaults = pkgs.lib.mapAttrs' (n: v: pkgs.lib.nameValuePair (pkgs.lib.removeSuffix "-latest" n) v) latest.published;
};
# Generate the packages from the manifest sets.
mkPackages = pkgs: let
manifests = mkManifests pkgs;
packageName = manifest: builtins.replaceStrings ["."] ["-"] "${manifest.pname}-${manifest.version}";
packageNameNightly = manifest: "${packageName manifest}-nightly-${manifest.date}";
buildRustPackage = manifest: let
rust-platform = pkgs.makeRustPlatform {
rustc = manifest.rust;
cargo = manifest.rust;
};
in
rust-platform.buildRustPackage manifest;
buildRustPackages = manifests: pkgs.lib.mapAttrs (n: m: buildRustPackage m) manifests;
packageAttr = manifest: {
name = packageName manifest;
value = buildRustPackage manifest;
};
packageAttrNightly = manifest: {
name = packageNameNightly manifest;
value = buildRustPackage manifest;
};
packageAttrMilestone = manifest: {
name = manifest.pname;
value = buildRustPackage manifest;
};
packagesPublished = builtins.listToAttrs (map packageAttr manifests.published.prepared);
packagesNightly = builtins.listToAttrs (map packageAttrNightly manifests.nightly.prepared);
packagesPublishedLatest = buildRustPackages manifests.latest.published;
packagesNightlyLatest = buildRustPackages manifests.latest.nightly;
packagesDefault = buildRustPackages manifests.defaults;
packagesMilestone = manifests: builtins.listToAttrs (map packageAttrMilestone manifests);
packagesMilestones = pkgs.lib.mapAttrs' (mn: mms: pkgs.lib.nameValuePair mn (packagesMilestone mms)) manifests.milestones;
packagesMilestonesAll = pkgs.lib.concatMapAttrs (_: pkgs: pkgs) packagesMilestones;
packagesMilestoneGroup = mstone: packages: rec {
name = "fuel-" + mstone;
value = pkgs.symlinkJoin {
inherit name;
paths = pkgs.lib.attrValues packages;
};
};
packagesMilestoneGroups = pkgs.lib.mapAttrs' packagesMilestoneGroup packagesMilestones;
packagesGroups =
rec {
fuel-latest = pkgs.symlinkJoin {
name = "fuel-latest";
paths = pkgs.lib.attrValues packagesPublishedLatest;
};
fuel-nightly = pkgs.symlinkJoin {
name = "fuel-nightly";
paths = pkgs.lib.attrValues packagesNightlyLatest;
};
fuel = fuel-latest;
default = fuel;
}
// packagesMilestoneGroups;
packagesOther = {
refresh-manifests = pkgs.writeShellApplication {
name = "refresh-manifests";
runtimeInputs = [
pkgs.coreutils # For `date` command
pkgs.git # Used to fetch the fuel repos.
pkgs.nix # Used to generate the package src sha256 hashes.
pkgs.semver-tool # Validate semver retrieved from git tags.
];
checkPhase = ""; # Temporarily disable check phase while devving.
text = builtins.readFile ./script/refresh-manifests.sh;
};
sway-vim = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "sway-vim";
version = "master";
src = inputs.sway-vim-src;
meta = {
homepage = "https://github.com/fuellabs/sway.vim";
license = pkgs.lib.licenses.mit;
};
};
};
in
packagesPublished
// packagesNightly
// packagesPublishedLatest
// packagesNightlyLatest
// packagesDefault
// packagesMilestonesAll
// packagesGroups
// packagesOther;
overlays = rec {
fuel = final: prev: let
fuelpkgs = mkPackages prev;
in {
inherit (fuelpkgs) fuel;
vimPlugins = prev.vimPlugins // {inherit (fuelpkgs) sway-vim;};
};
fuel-nightly = final: prev: let
fuelpkgs = mkPackages prev;
in {
inherit (fuelpkgs) fuel-nightly;
vimPlugins = prev.vimPlugins // {inherit (fuelpkgs) sway-vim;};
};
default = fuel;
};
mkDevShells = pkgs: fuelpkgs: rec {
book-dev = pkgs.mkShell {
name = "book-dev";
buildInputs = [pkgs.mdbook];
};
fuel-core-dev = pkgs.mkShell {
name = "fuel-core-dev";
inputsFrom = with fuelpkgs; [
fuel-core-nightly
fuel-gql-cli-nightly
];
buildInputs = [pkgs.grpc-tools];
inherit (fuelpkgs.fuel-core-nightly) LIBCLANG_PATH ROCKSDB_LIB_DIR;
PROTOC = "${pkgs.grpc-tools}/bin/protoc";
NIX_CFLAGS_COMPILE = fuelpkgs.fuel-core-nightly.NIX_CFLAGS_COMPILE or "";
};
sway-dev = pkgs.mkShell {
name = "sway-dev";
inputsFrom = with fuelpkgs; [
forc-nightly
forc-client-nightly
forc-doc-nightly
forc-fmt-nightly
forc-lsp-nightly
forc-tx-nightly
];
buildInputs = with fuelpkgs; [fuel-core fuel-gql-cli];
};
fuel-dev = pkgs.mkShell {
name = "fuel-dev";
inputsFrom = let
isCurrentNightly = name: name != "fuel-nightly" && pkgs.lib.hasSuffix "nightly" name;
currentNightlies = pkgs.lib.filterAttrs (n: v: isCurrentNightly n) fuelpkgs;
in
(pkgs.lib.mapAttrsToList (n: v: v) currentNightlies) ++ [fuel-core-dev sway-dev];
inherit (fuel-core-dev) LIBCLANG_PATH ROCKSDB_LIB_DIR PROTOC NIX_CFLAGS_COMPILE;
};
default = fuel-dev;
};
mkOutput = system: let
overlays = [inputs.rust-overlay.overlays.default];
pkgs = import inputs.nixpkgs {inherit overlays system;};
in rec {
packages = mkPackages pkgs;
devShells = mkDevShells pkgs packages;
formatter = pkgs.alejandra;
};
# The output for each system.
systemOutputs = utils.eachSupportedSystem mkOutput;
in
# Merge the outputs and overlays.
systemOutputs // {inherit overlays utils;};
}