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
| | # SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021-2022 Alyssa Ross <hi@alyssa.is>
{ config ? import ../../nix/eval-config.nix {}
, terminfo ? config.pkgs.foot.terminfo
}:
config.pkgs.pkgsStatic.callPackage (
{ lib, stdenvNoCC, runCommand, writeReferencesToFile, buildPackages
, jq, s6-rc, tar2ext4, util-linux
, busybox, cacert, execline, kmod, mdevd, s6, s6-linux-init
}:
let
inherit (lib) cleanSource cleanSourceWith concatMapStringsSep hasSuffix;
scripts = import ../../scripts { inherit config; };
packages = [
execline kmod mdevd s6 s6-linux-init s6-rc
(busybox.override {
extraConfig = ''
CONFIG_DEPMOD n
CONFIG_INSMOD n
CONFIG_LSMOD n
CONFIG_MODINFO n
CONFIG_MODPROBE n
CONFIG_RMMOD n
'';
})
];
packagesSysroot = runCommand "packages-sysroot" {
inherit packages;
passAsFile = [ "packages" ];
} ''
mkdir -p $out/usr/bin $out/usr/share
ln -s ${concatMapStringsSep " " (p: "${p}/bin/*") packages} $out/usr/bin
ln -s ${kernel}/lib "$out"
ln -s ${terminfo}/share/terminfo $out/usr/share
ln -s ${cacert}/etc/ssl $out/usr/share
'';
packagesTar = runCommand "packages.tar" {} ''
cd ${packagesSysroot}
tar -cf $out --verbatim-files-from \
-T ${writeReferencesToFile packagesSysroot} .
'';
kernel = buildPackages.linux_latest.override {
structuredExtraConfig = with lib.kernel; {
VIRTIO = yes;
VIRTIO_PCI = yes;
VIRTIO_BLK = yes;
VIRTIO_CONSOLE = yes;
DRM_VIRTIO_GPU = yes;
EXT4_FS = yes;
DRM_BOCHS = yes;
DRM = yes;
AGP = yes;
};
};
in
stdenvNoCC.mkDerivation {
name = "spectrum-appvm";
src = cleanSourceWith {
filter = name: _type:
name != "${toString ./.}/build" &&
!(hasSuffix ".nix" name);
src = cleanSource ./.;
};
nativeBuildInputs = [ jq s6-rc tar2ext4 util-linux ];
PACKAGES_TAR = packagesTar;
VMLINUX = "${kernel.dev}/vmlinux";
makeFlags = [ "SCRIPTS=${scripts}" "prefix=$(out)" ];
enableParallelBuilding = true;
passthru = { inherit kernel packagesSysroot; };
meta = with lib; {
license = licenses.eupl12;
platforms = platforms.linux;
};
}
) {}
|