Monorepo for Tangled
tangled.org
1{
2 pkgs,
3 lib,
4 nixosSystem,
5}: let
6 system = nixosSystem.pkgs.stdenv.hostPlatform.qemuArch;
7 microvm = nixosSystem.config.microvm;
8 baseConfigHash = lib.pipe nixosSystem.config.system.build.toplevel.outPath [
9 (lib.strings.removePrefix "/nix/store/")
10 (lib.strings.splitString "-")
11 lib.head
12 ];
13 imageSpecJSON = pkgs.writeText "spec.json" (
14 builtins.toJSON {
15 arch = system;
16 bootArgs = "earlyprintk=ttyS0 console=hvc0 reboot=t panic=-1 ${lib.concatStringsSep " " microvm.kernelParams}";
17 kernel = "kernel";
18 initrd = "initrd";
19 runnerType = "qemu";
20 runnerConfig = {
21 cpu = "host,+x2apic,-sgx";
22 machine = "microvm,accel=kvm:tcg,acpi=on,mem-merge=on,pcie=off,pic=off,pit=off,rtc=on,usb=off";
23 console = "hvc0";
24 extraArgs = [];
25 };
26 memoryMiB = microvm.mem;
27 storeDisk = "store-disk";
28 storeDiskType = microvm.storeDiskType;
29 vcpus = microvm.vcpu;
30 shell = "/run/current-system/sw/bin/bash";
31 baseConfigHash = baseConfigHash;
32 networkInterfaces =
33 map (interface: {
34 type = "slirp4netns";
35 id = interface.id;
36 mac = interface.mac;
37 })
38 microvm.interfaces;
39 volumes =
40 map (volume: {
41 fsType = volume.fsType;
42 image = volume.image;
43 imageType = volume.imageType;
44 mountPoint = volume.mountPoint;
45 readOnly = volume.readOnly;
46 sizeMiB = volume.size;
47 })
48 microvm.volumes;
49 }
50 );
51in
52 pkgs.runCommand "spindle-nixos-image-${system}" {} ''
53 mkdir -p "$out"
54 cp ${imageSpecJSON} "$out/spec.json"
55 ln -s ${microvm.kernel}/bzImage "$out/kernel"
56 ln -s ${microvm.initrdPath} "$out/initrd"
57 ln -s ${microvm.storeDisk} "$out/store-disk"
58 ''