Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
295 lines (273 loc) · 9.52 KB
/
Copy pathflake.nix
File metadata and controls
295 lines (273 loc) · 9.52 KB
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
{
inputs = {
nix-jettison.url = "git+ssh://git@github.com/noib3/nix-jettison.git";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nix-jettison,
nixpkgs,
rust-overlay,
treefmt-nix,
...
}:
let
forEachSystem =
f:
nixpkgs.lib.genAttrs [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
] (system: f system nixpkgs.legacyPackages.${system});
mkToolchain =
pkgs:
((rust-overlay.lib.mkRustBin { } pkgs.buildPackages).fromRustupToolchainFile
./rust-toolchain.toml
).override
{
targets = [ pkgs.stdenv.targetPlatform.rust.rustcTarget ];
};
mkBuildInputs =
pkgs:
let
# HEAD of https://github.com/NixOS/nix/pull/15675
nixSource = pkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nix";
rev = "9d718847a1b97cc8476cb23c207cacf91ba136ed";
sha256 = "11cnvlsfv1wimhljdb5483kfd3gg3vijixf38lzssh4l3c3h7z2l";
};
components =
(
(pkgs.pkgsStatic.nixDependencies.callPackage
"${nixpkgs}/pkgs/tools/package-management/nix/modular/packages.nix"
{
src = nixSource;
version = "2.35.0";
otherSplices = pkgs.pkgsStatic.generateSplicesForMkScope [
"nixVersions"
"nixComponents_git"
];
teams = [ ];
}
).appendPatches
[
./nix/patches/nix-store-optional-curl.patch
# Keep the C API pkg-config files from exposing internal C++
# libraries as public link dependencies.
./nix/patches/nix-libutil-c-pkg-config-private-deps.patch
./nix/patches/nix-libstore-c-pkg-config-private-deps.patch
# Fix static pkg-config metadata so downstream consumers link
# Boost and the C++ runtime correctly.
./nix/patches/nix-libutil-pkg-config-static-libs.patch
./nix/patches/nix-libstore-pkg-config-static-libs.patch
]
).overrideScope
(
final: prev: {
nix-util = (prev.nix-util).overrideAttrs (old: {
propagatedBuildInputs = pkgs.lib.filter (
pkg: (pkg.pname or "") != "libarchive"
) old.propagatedBuildInputs;
mesonFlags = old.mesonFlags ++ [
(pkgs.lib.mesonBool "archive-support" false)
];
});
nix-util-c = (
prev.nix-util-c.override {
nix-util = final.nix-util;
}
);
nix-store =
(prev.nix-store.override {
nix-util = final.nix-util;
# nixpkgs currently enables the embedded sandbox shell for
# all static builds, but only wires the busybox sandbox
# shell path on Linux. Disable the embedded shell on
# non-Linux targets so the static package still builds.
embeddedSandboxShell =
pkgs.stdenv.hostPlatform.isLinux && pkgs.stdenv.hostPlatform.isStatic;
# We don't need authenticated S3 fetcher support, so let's
# disable it to make the release binary smaller.
withAWS = false;
}).overrideAttrs
(old: {
propagatedBuildInputs = pkgs.lib.filter (
pkg: (pkg.pname or "") != "curl"
) old.propagatedBuildInputs;
buildInputs = pkgs.lib.remove prev.curl old.buildInputs;
mesonFlags = old.mesonFlags ++ [
(pkgs.lib.mesonBool "http-client" false)
(pkgs.lib.mesonBool "extra-store-implementations" false)
];
});
nix-store-c = (
prev.nix-store-c.override {
nix-util-c = final.nix-util-c;
nix-store = final.nix-store;
}
);
}
);
in
[
components.nix-util.dev
components.nix-util-c.dev
components.nix-store.dev
components.nix-store-c.dev
];
# Darwin's wrapped toolchain still injects the shared libiconv search
# path via NIX_LDFLAGS. Rewrite those flags so `-liconv` resolves to the
# static archive in both the dev shell and packaged builds.
mkStaticLinkEnvHook =
pkgs:
pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
rewrite_iconv_flags() {
local var_name=$1
local value="''${!var_name:-}"
local rewritten=
for flag in $value; do
case "$flag" in
-liconv)
flag='${pkgs.pkgsStatic.libiconv.dev}/lib/libiconv.a'
;;
-L*-libiconv-*)
case "$flag" in
*-static-*) ;;
*) continue ;;
esac
;;
esac
rewritten="$rewritten $flag"
done
printf -v "$var_name" '%s' "''${rewritten# }"
export "$var_name"
}
rewrite_iconv_flags NIX_LDFLAGS
rewrite_iconv_flags NIX_LDFLAGS_FOR_BUILD
'';
mkWorkspace =
pkgs:
import ./nix/workspace.nix {
inherit pkgs self nix-jettison;
nixLibraries = mkBuildInputs pkgs;
toolchain = mkToolchain pkgs;
};
mkPackage =
pkgs:
(mkWorkspace pkgs).rootPackage.build.override {
binaries = true;
features = [ "sub60-cache" ];
};
mkTreefmt =
pkgs:
treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.nixfmt = {
enable = true;
width = 80;
};
programs.prettier.enable = true;
programs.rustfmt = {
enable = true;
package = mkToolchain pkgs;
};
settings.formatter.prettier.options = [
"--config"
"${./prettier.config.json}"
];
settings.formatter.rustfmt.options = [
"--config-path"
"${./rustfmt.toml}"
];
};
in
{
packages = forEachSystem (
_system: pkgs:
{
default = mkPackage pkgs;
aarch64-linux = mkPackage pkgs.pkgsCross.aarch64-multiplatform-musl;
x86_64-linux = mkPackage pkgs.pkgsCross.musl64;
}
// nixpkgs.lib.optionalAttrs (pkgs.stdenv.buildPlatform.isDarwin) {
aarch64-darwin = mkPackage pkgs.pkgsCross.aarch64-darwin;
x86_64-darwin = mkPackage pkgs.pkgsCross.x86_64-darwin;
}
);
# Workaround for https://github.com/NixOS/nix/issues/8881 so that we
# can run individual checks with `nix run .#check-<foo>`.
apps = forEachSystem (
system: pkgs:
nixpkgs.lib.mapAttrs' (name: check: {
name = "check-${name}";
value = {
type = "app";
program =
(pkgs.writeShellScript "check-${name}" ''
# Force evaluation of ${check}.
echo -e "\033[1;32m✓\033[0m Check '${name}' passed"
'').outPath;
};
}) self.checks.${system}
);
devShells = forEachSystem (
_system: pkgs: {
default = pkgs.mkShell {
buildInputs = mkBuildInputs pkgs;
nativeBuildInputs = [
((mkToolchain pkgs).override {
extensions = [
"clippy"
"rust-analyzer"
"rust-src"
"rustfmt"
];
})
pkgs.buildPackages.pkg-config
(mkTreefmt pkgs).config.build.programs.prettier
pkgs.nodejs
pkgs.typescript-language-server
];
shellHook = mkStaticLinkEnvHook pkgs;
env.PKG_CONFIG_ALL_STATIC = "1";
};
}
);
formatter = forEachSystem (
_system: pkgs: (mkTreefmt pkgs).config.build.wrapper
);
checks = forEachSystem (
_system: pkgs: {
clippy = (mkWorkspace pkgs).clippy.override {
allFeatures = true;
allTargets = true;
clippyArgs = [
"-D"
"warnings"
];
};
formatting = (mkTreefmt pkgs).config.build.check self;
}
);
};
nixConfig = {
extra-substituters = [
"https://cache.sub60.dev/sub60/setup-cache"
"https://cache.sub60.dev/noib3/nix-jettison"
];
extra-trusted-public-keys = [
"cache.sub60.dev/sub60/setup-cache-1:eLhgNfgMDRVlQ9EpHGWujSfjLZg21EGTd+lDCOuV0jY="
"cache.sub60.dev/noib3/nix-jettison-1:yFjuL2ZV5kv1FDUlU76T6yEh6/i7Ud3qF+QxgdZt0Ko="
];
};
}