-
Notifications
You must be signed in to change notification settings - Fork 92
/
flake.nix
168 lines (144 loc) · 4.45 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
{
description = "A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.";
inputs = { };
nixConfig = {
extra-substituters = [ "https://crane.cachix.org" ];
extra-trusted-public-keys = [ "crane.cachix.org-1:8Scfpmn9w+hGdXH/Q9tTLiYAE/2dnJYRJP7kl80GuRk=" ];
};
outputs = { ... }:
let
mkLib = pkgs: import ./default.nix {
inherit pkgs;
};
nodes = (builtins.fromJSON (builtins.readFile ./test/flake.lock)).nodes;
inputFromLock = name:
let
locked = nodes.${name}.locked;
in
fetchTarball {
url = "https://github.com/${locked.owner}/${locked.repo}/archive/${locked.rev}.tar.gz";
sha256 = locked.narHash;
};
eachSystem = systems: f:
let
# Merge together the outputs for all systems.
op = attrs: system:
let
ret = f system;
op = attrs: key: attrs //
{
${key} = (attrs.${key} or { })
// { ${system} = ret.${key}; };
}
;
in
builtins.foldl' op attrs (builtins.attrNames ret);
in
builtins.foldl' op { } systems;
eachDefaultSystem = eachSystem [
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
"x86_64-linux"
];
in
{
inherit mkLib;
overlays.default = _final: _prev: { };
templates = rec {
alt-registry = {
description = "Build a cargo project with alternative crate registries";
path = ./examples/alt-registry;
};
build-std = {
description = "Build a cargo project while also compiling the standard library";
path = ./examples/build-std;
};
cross-musl = {
description = "Building static binaries with musl";
path = ./examples/cross-musl;
};
cross-rust-overlay = {
description = "Cross compiling a rust program using rust-overlay";
path = ./examples/cross-rust-overlay;
};
cross-windows = {
description = "Cross compiling a rust program for windows";
path = ./examples/cross-windows;
};
custom-toolchain = {
description = "Build a cargo project with a custom toolchain";
path = ./examples/custom-toolchain;
};
end-to-end-testing = {
description = "Run End-to-End tests for a webapp";
path = ./examples/end-to-end-testing;
};
default = quick-start;
quick-start = {
description = "Build a cargo project";
path = ./examples/quick-start;
};
quick-start-simple = {
description = "Build a cargo project without extra checks";
path = ./examples/quick-start-simple;
};
quick-start-workspace = {
description = "Build a cargo workspace with hakari";
path = ./examples/quick-start-workspace;
};
sqlx = {
description = "Build a cargo project which uses SQLx";
path = ./examples/sqlx;
};
trunk = {
description = "Build a trunk project";
path = ./examples/trunk;
};
trunk-workspace = {
description = "Build a workspace with a trunk member";
path = ./examples/trunk-workspace;
};
};
} // eachDefaultSystem (system:
let
nixpkgs = inputFromLock "nixpkgs";
pkgs = import nixpkgs {
inherit system;
};
myLib = mkLib pkgs;
checks =
let
pkgsChecks = import nixpkgs {
inherit system;
overlays = [
(import (inputFromLock "rust-overlay"))
];
};
in
pkgsChecks.callPackages ./checks {
pkgs = pkgsChecks;
myLib = mkLib pkgsChecks;
myLibCross = mkLib (import nixpkgs {
localSystem = system;
crossSystem = "wasm32-wasi";
});
};
in
{
inherit checks;
packages = import ./pkgs {
inherit pkgs myLib;
};
formatter = pkgs.nixpkgs-fmt;
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
jq
mdbook
nix-eval-jobs
nixpkgs-fmt
taplo
];
};
});
}