Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
844 lines (788 loc) · 34.4 KB
/
Copy pathflake.nix
File metadata and controls
844 lines (788 loc) · 34.4 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
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
{
description = "A Flake of my NixOS machines";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
# <https://github.com/nix-systems/nix-systems>
systems.url = "github:nix-systems/default-linux";
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs";
};
shuba-cursors = {
url = "github:RossComputerGuy/shuba-cursors";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-apple-silicon = {
url = "github:nix-community/nixos-apple-silicon";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
cosmic-manager = {
url = "github:HeitorAugustoLN/cosmic-manager";
inputs = {
nixpkgs.follows = "nixpkgs";
home-manager.follows = "home-manager";
};
};
darwin = {
url = "github:lnl7/nix-darwin/master";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-hardware.url = "github:NixOS/nixos-hardware";
# The FydeTab Duo work is not upstream yet.
nixos-hardware-fydetab.url = "github:RossComputerGuy/nixos-hardware/feat/fydetabduo-kernel-patches";
disko.url = "github:nix-community/disko";
determinate.url = "https://flakehub.com/f/DeterminateSystems/determinate/*";
nixvim = {
url = "github:nix-community/nixvim";
inputs = {
nixpkgs.follows = "nixpkgs";
systems.follows = "systems";
};
};
lanzaboote = {
url = "github:nix-community/lanzaboote";
inputs.nixpkgs.follows = "nixpkgs";
};
microvm = {
url = "github:astro/microvm.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
chock = {
url = "git+https://git.lilithsemi.com/LilithSemi/chock.git";
inputs.nixpkgs.follows = "nixpkgs";
};
# Puts qBittorrent in a network namespace whose only route out is the
# Mullvad tunnel. It has no inputs of its own.
vpn-confinement.url = "github:Maroka-chan/VPN-Confinement";
nixos-vault-service = {
url = "github:DeterminateSystems/nixos-vault-service";
inputs.nixpkgs.follows = "nixpkgs";
};
stylix = {
url = "github:nix-community/stylix";
inputs = {
nixpkgs.follows = "nixpkgs";
nur.follows = "nur";
systems.follows = "systems";
};
};
# The palette, as sources and not as a package. modules/theme.nix used to
# name a file inside pkgs.base16-schemes, and stylix reads that file while
# it evaluates. So Nix had to build base16-schemes for the machine's own
# platform before it could evaluate the machine at all, and a riscv64
# machine could then only be evaluated on riscv64 hardware. A source path
# needs no build, so every machine now evaluates from any machine.
#
# The repository is "schemes" and the files are below base16/. The nixpkgs
# package renames that directory to share/themes, which is why the old path
# looked different.
base16-schemes = {
url = "github:tinted-theming/schemes";
flake = false;
};
};
nixConfig = rec {
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
#"cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g="
"cosmic.cachix.org-1:Dya9IyXD4xdBehWjrkPv6rtxpmMdRel02smYzA85dPE="
"argama-1:D/CZ1iVEV+tjTUcYklCVGGhOkxHtx6M8B5j6hBYuSEk="
];
substituters = [
"https://cache.nixos.org"
#"https://cache.garnix.io"
"https://cosmic.cachix.org"
# Plain HTTP on purpose. The Nix daemon needs a certificate authority in
# its trust store before it starts, and OpenBao gives a machine argama's
# authority long after that. TLS adds nothing here either, because every
# store path carries a signature which the key above checks. A changed
# byte on the wire fails that check, so the transport carries no trust.
#
# The name resolves through argama's own DNS only. A machine that cannot
# reach it logs a warning for each query and carries on, because fallback
# is true below.
"http://cache.argama.nix"
];
trusted-substituters = substituters;
fallback = true;
};
outputs =
{
self,
nur,
home-manager,
nixpkgs,
darwin,
nixos-apple-silicon,
shuba-cursors,
nixos-hardware,
disko,
determinate,
nixvim,
lanzaboote,
stylix,
...
}@inputs:
let
inherit (nixpkgs) lib;
overlays = {
nur = nur.overlays.default;
apple-silicon = nixos-apple-silicon.overlays.default;
chock = inputs.chock.overlays.default;
default = (
final: prev: {
# Ross's fork adds a libcosmic editing and censoring UI, so this
# needs the full libcosmic build inputs, not only a new source.
# overrideAttrs cannot regenerate the vendored crates of a
# buildRustPackage, so cargoDeps is replaced here. The cargoHash is
# a placeholder: run the build once and set it from the error.
cosmic-screenshot = prev.cosmic-screenshot.overrideAttrs (
f: p: {
version = "1.11.0-editing";
src = final.fetchFromGitHub {
owner = "RossComputerGuy";
repo = "cosmic-screenshot";
rev = "ab6401acc695d922861b0917106bfbad05d73398";
hash = "sha256-rVFBVcFOnOCNsEXSudgQ/SgOXiadgv4ccHvar68OQNE=";
};
cargoDeps = final.rustPlatform.fetchCargoVendor {
inherit (f) src;
name = "cosmic-screenshot-1.11.0-editing";
hash = "sha256-2o+Ont23htlxq41LobgZOchEUhRfPT7adr2fWW9/oIg=";
};
nativeBuildInputs = (p.nativeBuildInputs or [ ]) ++ [
final.libcosmicAppHook
];
buildInputs = (p.buildInputs or [ ]) ++ [
final.glib
final.fontconfig
final.freetype
];
}
);
shuba-cursors = final.stdenv.mkDerivation {
pname = "shuba-cursors";
version = "git-${inputs.shuba-cursors.shortRev or "dirty"}";
src = lib.cleanSource inputs.shuba-cursors;
installPhase = ''
install -dm 755 $out/share/icons/Shuba
cp -r cursors $out/share/icons/Shuba/cursors
cp index.theme $out/share/icons/Shuba/index.theme
'';
};
obs-studio-plugins = prev.obs-studio-plugins // {
wlrobs = prev.obs-studio-plugins.wlrobs.overrideAttrs (
f: p: {
meta = p.meta // {
platforms = [
"aarch64-linux"
"x86_64-linux"
];
};
}
);
};
# The dirty-log unit test in the block crate assumes 4K pages. The
# bitmap granularity comes from sysconf at build time, so on the
# 64K-page kernels of the Ampere machines (and the 16K pages of
# Asahi) one bit covers a whole page and the test's "page not
# transferred" assertion cannot hold. Over-marking dirty pages is
# safe for migration, so skip the test there. Drop the skip when
# upstream makes the test page-size aware.
cloud-hypervisor = prev.cloud-hypervisor.overrideAttrs (
f: p: {
cargoTestFlags =
p.cargoTestFlags or [ ]
++ lib.optionals final.stdenv.hostPlatform.isAarch64 [
"--skip=io_impl::request::tests::read_marks_survive_a_dirty_log_harvest_while_in_flight"
];
}
);
libdrm = prev.libdrm.override {
withValgrind =
!final.stdenv.hostPlatform.useLLVM
&& lib.meta.availableOn final.stdenv.hostPlatform final.valgrind-light;
};
linux-pam = prev.linux-pam.overrideAttrs (
f: p: {
env =
lib.optionalAttrs
(final.stdenv.cc.bintools.isLLVM && lib.versionAtLeast final.stdenv.cc.bintools.version "17")
{
NIX_LDFLAGS = "--undefined-version";
};
}
);
nettle = prev.nettle.overrideAttrs (
lib.optionalAttrs final.stdenv.hostPlatform.isStatic {
CCPIC = "-fPIC";
}
);
qemu-user = prev.qemu-user.overrideAttrs (
f: p:
lib.optionalAttrs final.stdenv.hostPlatform.isStatic {
configureFlags = p.configureFlags ++ [ "--disable-pie" ];
}
);
noto-fonts-color-emoji =
(prev.noto-fonts-color-emoji.override {
inherit (final.pkgsBuildBuild) nototools;
}).overrideAttrs
(
f: p: {
nativeBuildInputs = with final.buildPackages; [
imagemagick
zopfli
pngquant
which
python3Packages.fonttools
];
depsBuildBuild =
p.depsBuildBuild
++ (with final.pkgsBuildBuild; [
nototools
]);
}
);
ostree = prev.ostree.override {
withGjs = final.stdenv.hostPlatform == final.stdenv.buildPlatform;
};
ostree-full = prev.ostree-full.override {
withGjs = final.stdenv.hostPlatform == final.stdenv.buildPlatform;
};
nixos-render-docs = prev.nixos-render-docs.overrideAttrs (
f: p: {
patches = [ ];
}
);
# libapparmor 5.0.2 puts a variable length array in a union at block
# scope, in self_syscall_enabled_init_once. GCC takes that as an
# extension. Clang refuses it and says the extension will never be
# supported. The replacement is the same constant the line above
# assigns to total_size, so this only folds the value in place and
# the code keeps its meaning.
#
# Only clang needs it. Applied to every compiler it rebuilds
# libapparmor and then dbus, pcsclite, libfido2 and openssh above
# it, none of which can come from a cache after that.
libapparmor = prev.libapparmor.overrideAttrs (o: {
postPatch =
(o.postPatch or "")
+ lib.optionalString final.stdenv.cc.isClang ''
substituteInPlace src/kernel.c \
--replace-fail "char buff[total_size];" "char buff[sizeof(struct lsm_ctx) + 8];"
'';
});
# fonttools fails 68 tests under pkgsLLVM, and each one compares a
# float in text: it gets 0.037499999999999999 where it wants 0.0375.
# pkgsLLVM is a crossSystem, so configure takes a --host argument,
# and autoconf sets cross_compiling=yes because the argument is
# there rather than because the platforms differ. Python then cannot
# run its own test for short float repr and keeps the %.17g one.
# nixpkgs still runs the checks, because it compares the platforms
# and sees they match.
#
# Only pkgsLLVM needs this. That set has no cache anyway, while the
# ordinary one does, and pythonPackagesExtensions rebuilds every
# python package below it.
#
# zeta3a reaches it through boot.kernelPackages: nvidiaPackages
# comes from the same set, and nvidia-settings pulls gtk+3, pango,
# harfbuzz and fonttools after it.
pythonPackagesExtensions =
prev.pythonPackagesExtensions
++ lib.optional final.stdenv.hostPlatform.useLLVM (
pyfinal: pyprev: {
fonttools = pyprev.fonttools.overridePythonAttrs (_: {
doCheck = false;
});
}
)
# torch writes the path to ninja and to the C++ compiler into its
# own code for torch.compile and torch.utils.cpp_extension, and
# reads both from targetPackages. A two-platform cross set leaves
# pkgsTargetTarget empty, because it is only populated for a
# three-platform canadian cross. So packages.x86_64-linux.argama,
# which cross builds aarch64 from x86_64, stopped inside
# paperless's torch with "attribute 'ninja' missing" and took
# nix flake show with it. The cross set itself is the right
# source: its ninja and its compiler both produce target code.
++ lib.optional (final.stdenv.hostPlatform != final.stdenv.buildPlatform) (
pyfinal: pyprev: {
torch = pyprev.torch.override { targetPackages = final; };
}
)
++ lib.optional final.stdenv.hostPlatform.isAarch64 (
pyfinal: pyprev:
let
# This test blanks ocrmypdf.builtin_plugins.__path__ and then
# expects the explicit imports in _plugin_manager to resolve
# from sys.modules. That only holds once another test has
# called get_plugin_manager, and pytest-xdist is free to run
# this one first in a worker. The remaining plugin-manager
# tests cover the same registration path.
patchOcrmypdf =
p:
p.overridePythonAttrs (o: {
disabledTests = o.disabledTests ++ [
"test_builtins_registered_without_package_discovery"
];
});
# paperless-ngx calls .override { tesseract = tesseract5; }
# on ocrmypdf, so keep .override working and carry the test
# disable through it.
ocrmypdfFor =
base:
patchOcrmypdf base
// {
override = args: ocrmypdfFor (base.override args);
};
in
{
# Kaleido starts a bundled browser for these tests. It does
# not start on aarch64 in the build sandbox, and nixpkgs
# only skips this file on Darwin.
plotly = pyprev.plotly.overridePythonAttrs (p: {
disabledTestPaths = p.disabledTestPaths ++ [ "tests/test_optional/test_kaleido" ];
});
optuna = pyprev.optuna.overridePythonAttrs (p: {
disabledTestPaths = p.disabledTestPaths ++ [ "tests/visualization_tests" ];
});
ocrmypdf = ocrmypdfFor pyprev.ocrmypdf;
}
);
# nghttp2 1.70.0's template_test.cc includes <spanstream> and
# calls std::spanstream on every platform except Apple. libc++
# has no spanstream implementation at all, so the unit test
# cannot compile under pkgsLLVM. The library and the programs
# build without it. Only make check fails, and nixpkgs runs make
# check here for the same reason as fonttools above.
#
# Only pkgsLLVM needs this, for the same cache reason as
# fonttools. zeta3a reaches nghttp2 through boot.kernelPackages
# the same way: nvidiaPackages comes from the same set.
nghttp2 = prev.nghttp2.overrideAttrs (
f: p: {
doCheck = p.doCheck && !final.stdenv.hostPlatform.useLLVM;
}
);
# krb5 1.22.2 assigns the result of strchr on a const string to a
# char pointer in ccbase.c and ktbase.c. GCC reports this as
# -Wdiscarded-qualifiers, so nixpkgs already passes
# -Wno-error=discarded-qualifiers. Clang has no such option and
# instead reports the same code under
# -Wincompatible-pointer-types-discards-qualifiers, which
# -Werror=incompatible-pointer-types from krb5's configure turns
# into an error. Downgrade the clang name back to a warning.
# tzdata 2026f runs make check, whose now.ck step compares zones
# against the release date. Hydra built the native package while it
# passed, and that output stays cached. The pkgsLLVM set has no such
# cache, so it runs the check today, when zones like Phoenix and
# Vancouver have become identical, and now.ck exits 1. Skip the check
# under pkgsLLVM. Same cache reason as nghttp2 above.
tzdata = prev.tzdata.overrideAttrs (
f: p: {
doCheck = p.doCheck && !final.stdenv.hostPlatform.useLLVM;
}
);
# sqlite 3.54.0's devtest suite fails test/waliter.test under
# clang, 2 errors out of ~991k. The native build passes it and
# stays cached. Here sqlite reaches pkgsLLVM only as a build tool:
# it feeds python3, which the kernel and zfs modules build against,
# so this copy never runs a real database. Skip the check under
# pkgsLLVM. Same cache reason as nghttp2 above.
sqlite = prev.sqlite.overrideAttrs (
f: p: {
doCheck = p.doCheck && !final.stdenv.hostPlatform.useLLVM;
}
);
krb5 = prev.krb5.overrideAttrs (o: {
env =
o.env
// lib.optionalAttrs final.stdenv.cc.isClang {
NIX_CFLAGS_COMPILE =
o.env.NIX_CFLAGS_COMPILE + " -Wno-error=incompatible-pointer-types-discards-qualifiers";
};
});
# librsvg builds rsvg-convert with rustc, and that link runs
# through the native GCC wrapper while pkgsLLVM builds the GIO
# stack with clang. libselinux, pulled in by GIO, comes from the
# native set and leaves its libgcc_s references for runtime,
# where its RUNPATH finds them. rustc's -lgcc_s is dropped under
# --as-needed, so stop ld from resolving those references in the
# executable instead.
librsvg = prev.librsvg.overrideAttrs (
o:
lib.optionalAttrs final.stdenv.hostPlatform.useLLVM {
NIX_LDFLAGS = (o.NIX_LDFLAGS or "") + " --allow-shlib-undefined";
}
);
# chock's test/broker/git_push.zig drives a real git push against a
# server in the test and gives the askpass helper 8 seconds to
# answer. Under the load of the build sandbox on aarch64 the
# helper does not answer in time, and the test fails with
# "expected 1, found 0". chock's own CI runs the suite, so skip
# it here until the timing is fixed upstream.
chock = prev.chock.overrideAttrs (_: {
doCheck = false;
});
# argama runs paperless. One of its tests depends on the clock and
# the machine's time zone, and it fails with "AssertionError: 8 !=
# 7" whenever the two disagree about the date.
#
# The test overrides TIME_ZONE to America/Chicago, then compares the
# day of the document, which the consumer reads from the file's
# st_mtime, against the day of timezone.localtime(timezone.now()).
# The build log shows the consumer using -05:00 and reporting
# 2026-09-08 01:39, while the comparison value reported the 7th.
# That same instant is the 7th at -07:00, so the two halves of the
# test resolved different zones. It passes in the morning and fails
# in the evening, which is no basis for a build.
#
# nixpkgs already removes two flaky tests from this package the same
# way, so this follows that list rather than inventing a mechanism.
paperless-ngx = prev.paperless-ngx.overrideAttrs (
f: p: {
disabledTestPaths = p.disabledTestPaths ++ [
"src/documents/tests/test_consumer.py::TestConsumer::testNormalOperation"
];
}
);
}
);
};
systems = [
"aarch64-darwin"
"riscv64-linux"
"aarch64-linux"
"x86_64-linux"
];
nixpkgsFor = lib.genAttrs systems (
system:
import nixpkgs.outPath {
inherit system;
overlays = (builtins.attrValues overlays);
config = {
allowUnfree = true;
# Home Manager's input method module always builds a gtk2 immodule cache.
problems.handlers."gtk+".broken = "warn";
};
}
);
machines = {
argama = "aarch64-linux";
zeta3a = "aarch64-linux";
hizack-b = "aarch64-linux";
jegan = "riscv64-linux";
age = "aarch64-linux";
jeda = "aarch64-linux";
regz = "x86_64-linux";
mu-gundam = "riscv64-linux";
};
forAllMachines = func: lib.mapAttrs func machines;
# The machines Hydra builds every night, so argama holds their store paths
# before anybody rebuilds. harmonia serves argama's own store and nothing
# else, so a path argama has never seen cannot come from argama, and the
# client goes to cache.nixos.org over the internet instead.
#
# These four are here because people rebuild them. The rest are left out
# on purpose: jegan and mu-gundam are riscv64 and argama has no builder
# for that architecture, and regz is x86_64 for the same reason. See
# services.hydra.buildMachinesFiles in devices/argama/default.nix, which
# is empty.
cachedMachines = [
"argama"
"zeta3a"
"hizack-b"
"jeda"
];
machineCross = {
jegan = {
extraModules = [
"${nixos-hardware}/starfive/visionfive/v2/sd-image-installer.nix"
];
output = "sdImage";
};
};
machineConfig = {
# Only argama confines a service to a VPN namespace. Every machine gets
# the Vault agent, because they all read their secrets from
# vault.argama.nix.
argama.extraModules = [
inputs.vpn-confinement.nixosModules.default
inputs.chock.nixosModules.chock-daemon
];
};
users = [ "ross" ];
forAllUsers =
func:
lib.listToAttrs (
lib.lists.flatten (
lib.map (
system: lib.map (user: lib.nameValuePair ("${system}/${user}") (func system user)) users
) systems
)
);
darwinMachines = {
"Hizack" = "aarch64-darwin";
};
forAllDarwinMachines = func: lib.mapAttrs func darwinMachines;
homeManagerModules = [
nixvim.homeModules.nixvim
# Always present, on every home-manager path. Stylix's own auto import
# only fires when the OS level stylix is enabled, which leaves cross
# builds and nix-darwin without the module while modules/theme.nix
# still sets stylix options. system/default.nix turns the auto import
# off so this entry is never duplicated.
stylix.homeModules.stylix
];
mkMachine =
machine: localSystem: crossSystem: extraModules:
let
cfg = machineConfig.${machine} or { };
in
(cfg.nixpkgs or inputs.nixpkgs).lib.nixosSystem {
specialArgs = {
inherit inputs;
};
modules = [
{
documentation.nixos.enable = false;
home-manager.sharedModules = homeManagerModules;
# modules/theme.nix is a home-manager module as well as a NixOS
# one, and it names a file inside the base16-schemes input. The
# NixOS side of home-manager passes none of the outer arguments
# down, so without this the module has no inputs to read.
# homeConfigurations below already does the same thing.
home-manager.extraSpecialArgs = {
inherit inputs;
};
nixpkgs = {
overlays = (builtins.attrValues overlays);
inherit crossSystem localSystem;
config = {
allowUnfree = true;
# Home Manager's input method module always builds a gtk2 immodule cache.
problems.handlers."gtk+".broken = "warn";
};
};
}
(cfg.home-manager or inputs.home-manager).nixosModules.default
./system/default.nix
./system/linux/default.nix
./devices/${machine}/default.nix
nixvim.nixosModules.nixvim
lanzaboote.nixosModules.lanzaboote
stylix.nixosModules.stylix
inputs.nixos-vault-service.nixosModules.nixos-vault-service
]
# Determinate has no riscv64 support, so gate on the platform the
# machine runs, which is crossSystem when there is one and localSystem
# otherwise. The old test read crossSystem alone, and crossSystem is
# null for every nixosConfigurations entry, so jegan and mu-gundam
# took the module and failed with "attribute 'riscv64-linux' missing".
# Only the cross outputs under packages ever passed.
++ lib.optional (
(crossSystem.system or localSystem.system) != "riscv64-linux"
) determinate.nixosModules.default
++ (cfg.extraModules or [ ])
++ extraModules;
};
in
{
inherit overlays;
legacyPackages = nixpkgsFor;
packages = lib.genAttrs systems (
localSystem:
let
pkgs = nixpkgsFor.${localSystem};
in
lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux (
# riscv64 is a target here and never a builder. Building an aarch64
# machine from a riscv64 host needs CUDA and triton as build tools,
# and nixpkgs has neither for riscv64, so packages.riscv64-linux
# stopped at "Refusing to evaluate package" for argama and zeta3a.
# A riscv64 host still builds its own two machines natively, and the
# aarch64 and x86_64 hosts still build every machine, jegan and
# mu-gundam included, so nothing that can be built is lost.
lib.filterAttrs
(machine: _: localSystem != "riscv64-linux" || machines.${machine} == "riscv64-linux")
(
forAllMachines (
machine: crossSystem:
let
cfg = machineCross.${machine} or { };
nixos = mkMachine machine { system = localSystem; } { system = crossSystem; } (
cfg.extraModules or [ ]
);
drv = nixos.config.system.build.${cfg.output or "toplevel"};
in
drv
// {
passthru = (drv.passthru or { }) // {
inherit nixos;
};
}
)
)
)
//
lib.optionalAttrs
(builtins.elem localSystem [
"x86_64-linux"
"aarch64-linux"
])
{
# `opencode`: boots the sandbox microVM with the current
# directory shared in as /workspace, runs opencode against llama.cpp on
# zeta3a (bridged from the host with socat). The guest is a build input
# of this tool, not a machine, so it's defined inline.
opencode =
let
guest = inputs.nixpkgs.lib.nixosSystem {
system = localSystem;
specialArgs = { inherit inputs; };
modules = [
inputs.microvm.nixosModules.microvm
./microvm/opencode.nix
];
};
in
pkgs.writeShellApplication {
name = "opencode";
runtimeInputs = [
pkgs.openssh
pkgs.coreutils
pkgs.socat
];
text = ''
ws="$PWD"
# qemu user-net hostfwd: the guest's sshd is reachable on the
# host loopback here (see microvm.forwardPorts in the guest).
sshport=2222
# Persistent state (store overlay + home/auth) lives here and is
# reused between sessions.
statedir="''${XDG_CACHE_HOME:-$HOME/.cache}/opencode"
mkdir -p "$statedir"
# Ephemeral ssh identity, regenerated each run. Only the *public*
# key is shared into the VM (via the control dir); the private key
# never enters it, so the agent can't use it to reach anything.
rundir="$(mktemp -d)"
ctldir="$rundir/ctl"
mkdir -p "$ctldir"
cleanup() {
if [ -n "''${vmpid:-}" ]; then kill "$vmpid" 2>/dev/null || true; fi
if [ -n "''${socatpid:-}" ]; then kill "$socatpid" 2>/dev/null || true; fi
rm -rf "$rundir"
}
trap cleanup EXIT INT TERM
ssh-keygen -t ed25519 -N "" -q -f "$rundir/id" -C opencode
cp "$rundir/id.pub" "$ctldir/authorized_keys"
servepass="$(head -c 24 /dev/urandom | base64 | tr -dc 'A-Za-z0-9')"
( umask 077; printf 'OPENCODE_SERVER_USERNAME=opencode\nOPENCODE_SERVER_PASSWORD=%s\n' "$servepass" > "$ctldir/serve-env" )
serveurl="http://opencode:$servepass@127.0.0.1:4096"
( umask 077; printf '%s\n' "$serveurl" > "$statedir/serve-url" )
# The guest's microvm.extraArgsScript reads these at launch and
# attaches them as 9p shares (workspace = CWD, sandboxctl = key).
export OPENCODE_SANDBOX_WS="$ws"
export OPENCODE_SANDBOX_CTL="$ctldir"
socat TCP-LISTEN:5000,bind=127.0.0.1,reuseaddr,fork \
TCP:zeta3a.tailde5a8.ts.net:5000 &
socatpid=$!
# Boot headless; console goes to a log under the state dir.
( cd "$statedir" && exec ${guest.config.microvm.declaredRunner}/bin/microvm-run ) \
</dev/null >"$statedir/console.log" 2>&1 &
vmpid=$!
ssh_opts=(
-i "$rundir/id"
-p "$sshport"
-o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null
-o LogLevel=ERROR
-o ConnectTimeout=2
)
# Wait for boot + network + key install + sshd.
ready=
for _ in $(seq 1 120); do
if ! kill -0 "$vmpid" 2>/dev/null; then
echo "opencode: VM exited during boot; see $statedir/console.log" >&2
exit 1
fi
if ssh "''${ssh_opts[@]}" root@127.0.0.1 true 2>/dev/null; then
ready=1
break
fi
sleep 1
done
if [ -z "$ready" ]; then
echo "opencode: timed out waiting for VM ssh; see $statedir/console.log" >&2
exit 1
fi
echo "opencode: remote control at $serveurl (also in $statedir/serve-url)" >&2
# Drive opencode over ssh with a real PTY (so the TUI renders
# and resizes), in the shared workspace.
ssh -t "''${ssh_opts[@]}" root@127.0.0.1 'cd /workspace && exec opencode' || true
# Graceful shutdown; cleanup() force-kills if it lingers.
ssh "''${ssh_opts[@]}" root@127.0.0.1 'systemctl poweroff' 2>/dev/null || true
for _ in $(seq 1 15); do
kill -0 "$vmpid" 2>/dev/null || break
sleep 1
done
'';
};
}
);
homeConfigurations = forAllUsers (
system: user:
home-manager.lib.homeManagerConfiguration (rec {
pkgs = nixpkgsFor.${system};
extraSpecialArgs = {
inherit inputs;
};
modules = [
./users/${user}/home.nix
./users/${user}/home-${pkgs.stdenv.targetPlatform.parsed.kernel.name}.nix
]
++ homeManagerModules;
})
);
darwinConfigurations = forAllDarwinMachines (
machine: system:
darwin.lib.darwinSystem {
inherit system;
pkgs = nixpkgsFor.${system};
inputs = {
inherit darwin nixpkgs;
};
modules = [
{
home-manager.sharedModules = homeManagerModules;
# See the note beside the same line in mkMachine.
home-manager.extraSpecialArgs = {
inherit inputs;
};
}
home-manager.darwinModules.default
stylix.darwinModules.stylix
determinate.darwinModules.default
./system/default.nix
./system/darwin.nix
./devices/${machine}/default.nix
];
}
);
nixosConfigurations = forAllMachines (
machine: system: mkMachine machine { inherit system; } null [ ]
);
# What Hydra builds. Point a jobset at this flake and it fills argama's
# store, which harmonia then serves to the fleet. The list is
# cachedMachines above.
hydraJobs.nixos = lib.genAttrs cachedMachines (
machine: self.nixosConfigurations.${machine}.config.system.build.toplevel
);
};
}