-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflake.nix
More file actions
742 lines (709 loc) · 30.1 KB
/
Copy pathflake.nix
File metadata and controls
742 lines (709 loc) · 30.1 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
{
description = "nixgg — gg-style build accelerator using Nix CA derivations.";
nixConfig = {
extra-experimental-features = [
"ca-derivations"
"dynamic-derivations"
"configurable-impure-env"
];
extra-system-features = [ "builder-rpc-v0" ];
};
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Tracks NixOS/nix PR #15793 (builder-rpc-v0 / `nix store submit-output`),
# unmerged upstream.
inputs.nix-15793 = {
url = "github:NixOS/nix";
};
inputs.lua-src = {
url = "https://www.lua.org/ftp/lua-5.4.7.tar.gz";
flake = false;
};
inputs.fmt-src = {
url = "github:fmtlib/fmt/11.0.2";
flake = false;
};
inputs.mosh-src = {
url = "github:mobile-shell/mosh";
flake = false;
};
inputs.redis-src = {
url = "github:redis/redis/8.2.2";
flake = false;
};
inputs.ffmpeg-src = {
url = "https://ffmpeg.org/releases/ffmpeg-7.1.2.tar.xz";
flake = false;
};
inputs.gcc-src = {
url = "https://ftp.gnu.org/gnu/gcc/gcc-15.3.0/gcc-15.3.0.tar.xz";
flake = false;
};
inputs.llvm-src = {
# Monorepo checkout, not a release tarball: llvm/CMakeLists.txt
# include()s from sibling cmake/ and third-party/.
#
# 19.x not 18.1.8: 18.1.8's SmallVector.h needs <cstdint> transitively,
# which GCC 15 no longer pulls in; fixed upstream in llvm-project#101761.
url = "github:llvm/llvm-project/llvmorg-19.1.7";
flake = false;
};
inputs.postgresql-src = {
# Builds only src/backend; `-j` on that subdir hits a real
# recursive-make ordering race in PostgreSQL's own Makefile.global —
# sidestep with `make -C src/backend generated-headers` first, then a
# non-`-j` build.
url = "https://ftp.postgresql.org/pub/source/v17.2/postgresql-17.2.tar.gz";
flake = false;
};
inputs.qemu-src = {
url = "https://download.qemu.org/qemu-9.2.0.tar.xz";
flake = false;
};
inputs.linux-src = {
url = "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.12.tar.xz";
flake = false;
};
outputs =
{ self, nixpkgs, nix-15793, lua-src, fmt-src, mosh-src, redis-src, ffmpeg-src,
gcc-src, llvm-src, postgresql-src, qemu-src, linux-src }:
let
forEachSystem = f: builtins.mapAttrs (system: pkgs: f system pkgs) nixpkgs.legacyPackages;
in
{
packages = forEachSystem (
system: pkgs:
let
toolchain = {
gcc = pkgs.gcc;
bash = pkgs.bash;
coreutils = pkgs.coreutils;
gnumake = pkgs.gnumake;
nix = pkgs.nixVersions.stable;
};
patchedNix =
(nix-15793.packages.${system}.nix-cli
or nix-15793.packages.${system}.default);
nixStoreC = nix-15793.packages.${system}.nix-store-c;
nixUtilC = nix-15793.packages.${system}.nix-util-c;
# nix-15793's own devShell buildInputs, unfiltered rather than this
# flake's `pkgs`, to avoid an ABI/version mismatch between two
# nixpkgs pins. Unfiltered because configuring the top-level
# meson.build resolves every subproject's dependency() calls even
# though only libutil/libstore get built.
nixBuildInputs =
let
shell = nix-15793.devShells.${system}.default;
in
(shell.buildInputs or [ ]) ++ (shell.propagatedBuildInputs or [ ]);
nixHelpers = pkgs.runCommand "nixgg-nix" { } ''
cp -r ${./nix} $out
chmod -R u+w $out
cat > $out/toolchain.nix <<'EOF'
{
compilerRoot = "${toolchain.gcc}";
bashRoot = "${toolchain.bash}";
coreutilsRoot = "${toolchain.coreutils}";
}
EOF
'';
toolchainJson = pkgs.writeTextFile {
name = "nixgg-toolchain.json";
text = builtins.toJSON {
gcc = "${toolchain.gcc}";
bash = "${toolchain.bash}";
coreutils = "${toolchain.coreutils}";
nix = "${toolchain.nix}";
real_cc = "${toolchain.gcc}/bin/g++";
nix_helpers = "${nixHelpers}";
patched_nix = "${patchedNix}";
};
};
envShell = pkgs.writeTextFile {
name = "nixgg-env.sh";
executable = false;
text = ''
export NIXGG_COMPILER_ROOT="${toolchain.gcc}"
export NIXGG_BASH_ROOT="${toolchain.bash}"
export NIXGG_COREUTILS_ROOT="${toolchain.coreutils}"
export NIXGG_GNUMAKE_ROOT="${toolchain.gnumake}"
export NIXGG_REAL_CC="${toolchain.gcc}/bin/g++"
export NIXGG_NIX="${toolchain.nix}/bin/nix"
export NIXGG_NIX_HELPERS="${nixHelpers}"
export NIXGG_PATCHED_NIX="${patchedNix}"
export NIXGG_TOOLCHAIN_PATHS="${toolchain.gcc} ${toolchain.bash} ${toolchain.coreutils} ${toolchain.gnumake} ${toolchain.nix} ${nixHelpers} ${patchedNix}"
'';
};
moshEnv = pkgs.stdenv.mkDerivation {
name = "nixgg-mosh-env";
nativeBuildInputs = with pkgs; [
autoconf automake libtool pkg-config perl gnumake protobuf which
];
buildInputs = with pkgs; [ ncurses openssl zlib protobuf ];
dontUnpack = true;
installPhase = "mkdir -p $out";
};
fmtEnv = pkgs.stdenv.mkDerivation {
name = "nixgg-fmt-env";
nativeBuildInputs = with pkgs; [
cmake ninja gnumake pkg-config which
];
dontUnpack = true;
installPhase = "mkdir -p $out";
};
# Its own src (not the whole repo) so editing nix/*.nix, examples,
# or docs can't move this derivation's hash.
nixggBin = pkgs.buildGoModule {
pname = "nixgg";
version = "0";
src = ./go;
vendorHash = null;
doCheck = false;
postInstall = ''
mkdir -p $out/shims
# A shim only fires if a symlink with that exact name is on
# PATH; not exhaustive (the triple x version cross product is
# unbounded) — add more if a real project needs them.
# objtool/objcopy aren't compilers: they're per-object
# rewriters, reached only when a caller points the build's
# own tool variable (objtool=, OBJCOPY=) here — nothing
# resolves them via PATH otherwise. rustc IS reached via
# PATH (Kbuild's RUSTC default is a bare "rustc").
for t in ar c++ cc g++ gcc ranlib clang clang++ ld ld.bfd ld.gold ld.lld objtool objcopy rustc; do
ln -s ../bin/nixgg $out/shims/$t
done
for t in gcc g++ cc c++ ar ranlib ld; do
ln -s ../bin/nixgg $out/shims/x86_64-unknown-linux-gnu-$t
ln -s ../bin/nixgg $out/shims/x86_64-linux-gnu-$t
done
'';
};
# Output IS a .drv file (the "final link" drv submitted from
# inside the sandbox); consumers resolve via `builtins.outputOf`.
mkNixggBuild = import ./nix/mkNixggBuild.nix {
inherit (pkgs) lib stdenv mkShell coreutils gnumake bash;
gcc = toolchain.gcc;
nixgg = nixggBin;
nixHelpers = nixHelpers;
patchedNix = patchedNix;
};
# See nix/splitStdenv.nix's top comment for the mechanism.
splitStdenv = import ./nix/splitStdenv.nix {
inherit (pkgs) lib config stdenvNoCC;
inherit (pkgs) bash coreutils gnumake;
gcc = toolchain.gcc;
nixgg = nixggBin;
patchedNix = patchedNix;
nixpkgsPath = nixpkgs;
inherit system;
};
# splitAtBuild applied to real upstream nixpkgs packages, proving
# the "upgrade an existing nixpkgs derivation" story from
# README.md. mosh exercises autoreconfHook's setup-hook-injected
# phase; zstd's cmake graph execs its own gen_html binary
# mid-build, which a plain `.override` can't resolve inside the
# sandbox ("./gen_html: Permission denied") — fixed via
# splitStdenv's extraBuildAttrs pre-building gen_html and
# pointing cmake at the resolved binary.
dynDrvExamples = {
hello-dyndrv = pkgs.hello.override { stdenv = splitStdenv { stdenv = pkgs.stdenv; splitAtBuild = true; }; };
mosh-dyndrv = pkgs.mosh.override { stdenv = splitStdenv { stdenv = pkgs.stdenv; splitAtBuild = true; }; };
zstd-dyndrv = import ./examples/zstd-dyndrv {
inherit pkgs mkNixggBuild splitStdenv;
};
};
configureSrcFilterPresets = import ./nix/configureSrcFilterPresets.nix;
batchGroupPresets = import ./nix/batchGroupPresets.nix;
configureCacheExamples = {
hello-cache = pkgs.hello.override { stdenv = splitStdenv { stdenv = pkgs.stdenv; splitAtConfigure = true; }; };
zstd-cache = pkgs.zstd.override { stdenv = splitStdenv { stdenv = pkgs.stdenv; splitAtConfigure = true; }; };
# An edit to a source file the autotools preset excludes never
# touches configure's own input, so configure doesn't rerun.
# existenceStubs needs "src/hello.c" — hello's
# AC_CONFIG_SRCDIR argument, checked only for existence.
hello-cache-filtered = pkgs.hello.override {
stdenv = splitStdenv {
stdenv = pkgs.stdenv;
splitAtConfigure = true;
configureSrcFilter = {
includePatterns = configureSrcFilterPresets.autotools;
existenceStubs = [ "src/hello.c" ];
};
};
};
# zstd's CMakeLists.txt uses file(GLOB ...) so filtering can't
# preserve early-cutoff there; fmt lists sources explicitly, so
# filtering matters. Extra patterns beyond the cmake preset are
# real configure-time reads (README.md/ChangeLog.md baked into
# add_library, .pc.in/.cmake.in templates, test/ since
# BUILD_TESTING defaults on).
fmt-cache-filtered = pkgs.fmt.override {
stdenv = splitStdenv {
stdenv = pkgs.stdenv;
splitAtConfigure = true;
configureSrcFilter = {
includePatterns = configureSrcFilterPresets.cmake ++ [
"include/fmt/*.h"
"src/*.cc"
"README.md"
"ChangeLog.md"
"support/cmake/*.in"
"test"
"test/*"
"test/*/*"
];
};
};
};
};
dynDrvConfigureCacheExamples = {
hello-dyndrv-configure-cached = pkgs.hello.override {
stdenv = splitStdenv {
stdenv = pkgs.stdenv;
splitAtConfigure = true;
splitAtBuild = true;
configureSrcFilter = {
includePatterns = configureSrcFilterPresets.autotools;
existenceStubs = [ "src/hello.c" ];
};
};
};
mosh-dyndrv-configure-cached = pkgs.mosh.override {
stdenv = splitStdenv { stdenv = pkgs.stdenv; splitAtConfigure = true; splitAtBuild = true; };
};
# gen_html mid-build-exec problem (see dynDrvExamples above);
# here the fix must reach both the configure stage (cmake's
# Makefile generation) and the build stage (which restores the
# configure tree and would reconfigure with its own copy),
# hence extraAttrs applying to every stage rather than a
# role-specific hatch.
zstd-dyndrv-configure-cached =
let
genHtml = mkNixggBuild {
pname = "zstd-gen-html";
version = "0";
src = pkgs.zstd.src;
targets = [ { name = "gen_html"; path = "gen_html"; } ];
buildCommand = ''
cd contrib/gen_html
g++ -O2 -c gen_html.cpp -o gen_html.o
g++ gen_html.o -o gen_html
'';
};
genHtmlPatch = ''
substituteInPlace build/cmake/contrib/gen_html/CMakeLists.txt \
--replace-fail \
'add_executable(gen_html ''${GENHTML_DIR}/gen_html.cpp)' \
"" \
--replace-fail \
'DEPENDS gen_html COMMENT "Update zstd manual")' \
'COMMENT "Update zstd manual")' \
--replace-fail \
'set(GENHTML_BINARY ''${PROJECT_BINARY_DIR}/gen_html''${CMAKE_EXECUTABLE_SUFFIX})' \
'set(GENHTML_BINARY ${genHtml.package}/bin/gen_html)'
'';
in
pkgs.zstd.override {
stdenv = splitStdenv {
stdenv = pkgs.stdenv;
splitAtConfigure = true;
splitAtBuild = true;
extraAttrs = finalAttrs: old: old // {
postPatch = old.postPatch + genHtmlPatch;
};
};
};
# gdbm covers multi-output+filter together (hello alone only
# covers single-output+filter, zstd only multi-output+no-filter).
gdbm-dyndrv-configure-cached = pkgs.gdbm.override {
stdenv = splitStdenv {
stdenv = pkgs.stdenv;
splitAtConfigure = true;
splitAtBuild = true;
configureSrcFilter = {
includePatterns = configureSrcFilterPresets.autotools;
existenceStubs = [ "src/gdbmdefs.h" ];
};
};
};
};
# Each example is one entry: the directory to import and the args
# it needs beyond `mkNixggBuild`. The -shell attr is generated
# from this. Native equivalence is pinned by
# tests/drv-equivalence.sh.
moshArgs = {
inherit (pkgs)
autoconf automake libtool pkg-config perl protobuf which
gnum4 gnugrep gnused gawk file
ncurses openssl zlib abseil-cpp;
src = mosh-src;
};
redisArgs = {
inherit (pkgs) which pkg-config python3 lua gnugrep gnused gawk;
src = redis-src;
};
exampleDefs = {
hello = {
dir = ./dyn-drv/hello-mkbuild.nix;
args = { inherit (pkgs) lib; };
};
lua = {
dir = ./examples/lua;
args = { src = lua-src; };
};
# Same fixture; batchGroups collapses the whole ~30-TU liblua.a
# archive into one batch derivation instead of 30 compiles + 1
# archive.
lua-batch = {
dir = ./examples/lua;
args = {
src = lua-src;
batchGroups = [ { name = "lua"; patterns = [ "src/**/*.c" ]; } ];
};
};
fmt = {
dir = ./examples/fmt;
args = { inherit (pkgs) cmake ninja pkg-config; src = fmt-src; };
};
# fmt's own target IS the archive (libfmt.a), so tryBatchArchive
# refuses to batch it; expected to build with batching never
# actually engaging.
fmt-batch = {
dir = ./examples/fmt;
args = {
inherit (pkgs) cmake ninja pkg-config;
src = fmt-src;
batchGroups = [ { name = "fmt"; patterns = [ "src/*.cc" ]; } ];
};
};
mosh = {
dir = ./examples/mosh;
args = moshArgs;
};
# mosh-server is the link target, not any one archive, so
# batching engages for all 6 lib*.a archives.
mosh-batch = {
dir = ./examples/mosh;
args = moshArgs // {
batchGroups = [ { name = "mosh"; patterns = [ "src/*/*.cc" ]; } ];
};
};
redis = {
dir = ./examples/redis;
args = redisArgs;
};
# vendorDeps preset: 5 of deps/'s 7 subtrees are reachable from
# redis-server and batch cleanly (jemalloc needs MALLOC=jemalloc,
# unset here; linenoise is redis-cli-only and never archived).
redis-batch = {
dir = ./examples/redis;
args = redisArgs // {
batchGroups = [
{ name = "vendor"; patterns = batchGroupPresets.vendorDeps; }
];
};
};
ffmpeg = {
dir = ./examples/ffmpeg;
args = {
inherit (pkgs) pkg-config perl nasm yasm gnumake which;
src = ffmpeg-src;
};
};
# "**" (not "*") matters: subdirectories like libavcodec/h264/
# feed the same top-level archive, and batching requires EVERY
# member of an archive to match the same group
# (collectSameGroupMembers in go/internal/shim/batcharchive.go)
# or the whole archive falls back to per-TU.
#
# libavutil/libswscale each have two sources sharing a basename
# in different subdirs; colliding members get a deterministic
# "-2"/"-3" suffix (disambiguateOutNames) instead of clobbering
# one shared $objroot slot.
#
# libavcodec/libavformat/libavfilter's combined batch scripts
# exceed MAX_ARG_STRLEN (131072 bytes), fixed via
# Env["batchScript"] + passAsFile instead of Args
# (BatchArchiveJSON in go/internal/expr/batcharchive.go).
#
# libpostproc is disabled by this build's own configure flags,
# unrelated to batching; the other 7 archives batch correctly.
ffmpeg-batch = {
dir = ./examples/ffmpeg;
args = {
inherit (pkgs) pkg-config perl nasm yasm gnumake which;
src = ffmpeg-src;
batchGroups = [
{
name = "ffmpeg";
patterns = [
"libavdevice/**/*.c"
"libswresample/**/*.c"
"libswscale/**/*.c"
"libavutil/**/*.c"
"libavcodec/**/*.c"
"libavformat/**/*.c"
"libavfilter/**/*.c"
];
}
];
};
};
# libiberty/ built via its own standalone ./configure, not gcc's
# top-level multi-package configure.ac — sidesteps GMP/MPFR/MPC,
# LTO ar/ranlib decoration, thin archives, and mid-build
# gengtype/genmodes exec that a full cc1/cc1plus build would hit.
gcc = {
dir = ./examples/gcc;
args = { src = gcc-src; };
};
# Same target-is-the-archive limitation as fmt-batch
# (libiberty.a is the submission target); batching never engages.
gcc-batch = {
dir = ./examples/gcc;
args = {
src = gcc-src;
batchGroups = [ { name = "gcc"; patterns = [ "libiberty/*.c" ]; } ];
};
};
# Standalone ./configure && make -C src/backend (not `make
# world`). Never `make -j`: a real, nixgg-unrelated
# recursive-make ordering race in PostgreSQL's own
# Makefile.global.
postgresql = {
dir = ./examples/postgresql;
args = { inherit (pkgs) bison flex perl; src = postgresql-src; };
};
# meson+ninja, the one build-system genre no other example
# exercises; its codegen (QAPI, decodetree.py, tracetool.py) is
# pure find_program-driven Python/shell, never a compiled-and-
# exec'd QEMU binary, so no phase-chaining fix is needed here.
qemu = {
dir = ./examples/qemu;
args = {
inherit (pkgs) pkg-config meson ninja glib pixman ncurses zlib;
pythonWithMesonDeps = pkgs.python3.withPackages (ps: [ ps.distlib ps.setuptools ]);
src = qemu-src;
};
};
# Named `nix-full` (not `nix-util`, not bare `nix`) since it
# builds all of Nix, not just libutil; `nix` is already claimed
# by toolchain.nix in this same packages output.
nix-full = {
dir = ./examples/nix-full;
args = {
inherit (pkgs) meson ninja cmake bison flex busybox lsof;
# nixpkgs' own default llvm output has no llvm-config
# (that's the "dev" output) — reuse nix-15793's devShell
# llvm, which already resolved to "dev".
llvm = builtins.head (
builtins.filter (p: (p.pname or "") == "llvm") nix-15793.devShells.${system}.default.nativeBuildInputs
);
pkgConfig = pkgs.pkg-config;
buildInputs = nixBuildInputs;
src = nix-15793;
};
};
# libqemuutil.a is the one archive (of QEMU's 5) worth batching;
# the others have exactly 1 member or never go through `ar`
# (meson's "extract objects" passes .o files straight to the
# link line).
#
# QEMU's internal static libs are built with `ar csrDT` (thin)
# — first fixture to exercise thin-archive support: a thin
# batch archive writes its member objects into
# $out/lib/.nixgg-objs/ (a permanent store output) rather than a
# build-tmp scratch dir, so self-references survive after the
# sandbox is torn down.
qemu-batch = {
dir = ./examples/qemu;
args = {
inherit (pkgs) pkg-config meson ninja glib pixman ncurses zlib;
pythonWithMesonDeps = pkgs.python3.withPackages (ps: [ ps.distlib ps.setuptools ]);
src = qemu-src;
batchGroups = [
{
name = "qemuutil";
patterns = [
"util/*.c"
"stubs/*.c"
"qobject/*.c"
"qapi/*.c"
"crypto/*.c"
"trace/*.c"
"build/qapi/*.c"
"build/trace/*.c"
];
}
];
};
};
# A single sandbox derivation can't satisfy Kbuild's synchronous
# read-back-after-produce shape; see examples/linux-kernel's own
# docstring for why phase 2 is a plain stdenv.mkDerivation
# rather than another mkNixggBuild call.
linux-kernel = {
dir = ./examples/linux-kernel;
args = {
inherit (pkgs) stdenv flex bison elfutils pkg-config bc pkgsStatic cpio;
inherit nixggBin;
src = linux-src;
};
};
# Two sources, no single `src`: phase 1 builds the codegen
# tool, phase 2 execs it mid-build.
two-phase = {
dir = ./examples/two-phase;
args = {
codegenSrc = ./examples/two-phase/codegen;
appSrc = ./examples/two-phase/app;
};
};
# Minimal reproduction of the ar --thin mechanism QEMU's meson
# build exercises at scale.
thin-archive = {
dir = ./examples/thin-archive;
args = { inherit (pkgs) lib; };
};
# Two Rust crates built by make and bare rustc — the shape
# Kbuild uses, and the only one the rustc shim models. See
# its own docstring for what it covers that nothing else
# does.
rustc = {
dir = ./examples/rustc;
args = {
inherit (pkgs) rustc;
src = ./examples/rustc;
};
};
llvm = {
dir = ./examples/llvm;
args = {
inherit (pkgs) runCommand cmake ninja pkg-config python3 perl which
libffi libxml2 ncurses zlib;
src = llvm-src;
};
};
# phase1 (llvm-min-tblgen) links exactly 3 archives —
# libLLVMDemangle.a, libLLVMSupport.a, libLLVMTableGen.a — none
# of which are phase1's own link target.
#
# libLLVMSupport mixes plain .c/.S sources in with .cpp, and
# collectSameGroupMembers requires every input to ar's
# invocation to be a same-group pending member, so all three
# extensions must be listed, not just *.cpp.
#
# Support's combined batch script exceeds MAX_ARG_STRLEN —
# same Env["batchScript"]+passAsFile fix as ffmpeg-batch. phase1
# goes from 186 to 13 total derivations with all 3 archives
# batched.
llvm-batch = {
dir = ./examples/llvm;
args = {
inherit (pkgs) runCommand cmake ninja pkg-config python3 perl which
libffi libxml2 ncurses zlib;
src = llvm-src;
batchGroups = [
{
name = "llvm";
patterns = [
"llvm/lib/Demangle/**/*.cpp"
"llvm/lib/TableGen/**/*.cpp"
"llvm/lib/Support/**/*.cpp"
"llvm/lib/Support/**/*.c"
"llvm/lib/Support/**/*.S"
];
}
];
};
};
};
examples = builtins.mapAttrs
(_: def: import def.dir ({ inherit mkNixggBuild; } // def.args))
exampleDefs;
exampleResults = builtins.mapAttrs (_: e: e.package) examples;
exampleShells = pkgs.lib.mapAttrs' (n: e: pkgs.lib.nameValuePair "${n}-shell" e.shell) examples;
in
toolchain
// exampleResults
// exampleShells
// dynDrvExamples
// configureCacheExamples
// dynDrvConfigureCacheExamples
// {
llvm-min-tblgen = examples.llvm.llvm-min-tblgen.package;
llvm-tblgen = examples.llvm.llvm-tblgen.package;
llvm-min-tblgen-batch = examples.llvm-batch.llvm-min-tblgen.package;
llvm-tblgen-batch = examples.llvm-batch.llvm-tblgen.package;
two-phase-codegen = examples.two-phase.codegen.package;
# phase2 is a plain stdenv.mkDerivation with no shims, so only
# phase1 exposes the full mkNixggBuild attrset (not just .package).
linux-kernel-phase1 = examples.linux-kernel.linux-kernel-phase1;
linux-kernel-phase1-shell = examples.linux-kernel.linux-kernel-phase1.shell;
linux-kernel-initramfs = examples.linux-kernel.linux-kernel-initramfs;
mosh-client = examples.mosh.packages.mosh-client;
toolchain-json = toolchainJson;
env-shell = envShell;
mosh-env = moshEnv;
fmt-env = fmtEnv;
patched-nix = patchedNix;
nix-store-c = nixStoreC;
nix-util-c = nixUtilC;
nixgg-bin = nixggBin;
inherit mkNixggBuild;
inherit splitStdenv;
inherit configureSrcFilterPresets;
default = envShell;
}
);
devShells = forEachSystem (system: pkgs:
let
pkgs' = self.packages.${system};
# No `gcc` in packages: the cc-wrapper's setup hook injects
# NIX_CFLAGS_COMPILE/NIX_LDFLAGS with a per-invocation
# -frandom-seed and a workspace-relative -rpath, breaking CA hash
# stability across shell entries. The shim resolves the real
# compiler via NIXGG_COMPILER_ROOT instead.
nixggShell = pkgs.mkShellNoCC {
name = "nixgg-shell";
packages = [
pkgs'.nixgg-bin
pkgs.gnumake
pkgs.coreutils
pkgs.bash
];
shellHook = ''
. ${pkgs'.env-shell}
: "''${NIXGG_STORE:=local?root=/tmp/nixgg-store}"
export NIXGG_STORE
# mkShellNoCC still synthesises its own $out, which can leak
# the same NIX_CFLAGS_COMPILE/NIX_LDFLAGS problem noted above.
unset NIX_CFLAGS_COMPILE NIX_CFLAGS_LINK NIX_LDFLAGS
export PATH="${pkgs'.nixgg-bin}/bin:${pkgs'.nixgg-bin}/shims:$PATH"
: "''${NIXGG_AUTOFORCE:=1}"
export NIXGG_AUTOFORCE
# An unpatched Nix fails opaquely (`attribute 'outputOf'
# missing` at eval, or a submit-output error mid-build).
echo "nixgg shell: prepending patched Nix and pointing NIX_CONFIG at an alt store — see README.md's 'Invoking sandbox mode explicitly'" >&2
export PATH="${pkgs'."patched-nix"}/bin:$PATH"
export NIX_CONFIG="
extra-experimental-features = ca-derivations dynamic-derivations configurable-impure-env
extra-system-features = builder-rpc-v0
store = ''${NIXGG_STORE}
"
echo "nixgg shell — 'nixgg --help', 'cc -v', 'which make', 'nix build .#hello'" >&2
'';
};
in
{
default = nixggShell;
mosh = pkgs'.mosh-env;
fmt = pkgs'.fmt-env;
});
apps = forEachSystem (system: pkgs:
let bin = "${self.packages.${system}.nixgg-bin}/bin/nixgg"; in
{
nixgg = { type = "app"; program = bin; };
default = { type = "app"; program = bin; };
});
};
}