# SPDX-License-Identifier: MIT # SPDX-FileCopyrightText: 2021-2023 Alyssa Ross import ../../../lib/call-package.nix ( { spectrum-build-tools, src, terminfo, pkgsMusl }: pkgsMusl.callPackage ( { lib, stdenvNoCC, nixos, runCommand, writeClosure , erofs-utils, jq, s6-rc, util-linux, xorg , busybox, dbus, execline, iwd, kmod, linuxPackagesFor, linux_latest , mdevd, nftables, s6, s6-linux-init, spectrum-driver-tools, xdp-tools }: let inherit (lib) concatMapStringsSep; inherit (nixosAllHardware.config.hardware) firmware; kernelTarget = if stdenvNoCC.hostPlatform.isx86 then # vmlinux.bin is the stripped version of vmlinux. # Confusingly, compressed/vmlinux.bin is the stripped version of # the top-level vmlinux target, while the top-level vmlinux.bin # is the stripped version of compressed/vmlinux. So we use # compressed/vmlinux.bin, since we want a stripped version of # the kernel that *hasn't* been built to be compressed. Weird! "compressed/vmlinux.bin" else kernel.target; kernel = (linux_latest.override { structuredExtraConfig = with lib.kernel; { DRM_FBDEV_EMULATION = lib.mkForce no; EROFS_FS = yes; FONTS = lib.mkForce unset; FONT_8x8 = lib.mkForce unset; FONT_TER16x32 = lib.mkForce unset; FRAMEBUFFER_CONSOLE = lib.mkForce unset; FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER = lib.mkForce unset; FRAMEBUFFER_CONSOLE_DETECT_PRIMARY = lib.mkForce unset; FRAMEBUFFER_CONSOLE_ROTATION = lib.mkForce unset; RC_CORE = lib.mkForce unset; VIRTIO = yes; VIRTIO_BLK = yes; VIRTIO_CONSOLE = yes; VIRTIO_PCI = yes; VT = no; }; }).overrideAttrs ({ installFlags ? [], ... }: { installFlags = installFlags ++ [ "KBUILD_IMAGE=$(boot)/${kernelTarget}" ]; }); packages = [ dbus execline kmod mdevd s6 s6-linux-init s6-rc xdp-tools (busybox.override { extraConfig = '' CONFIG_DEPMOD n CONFIG_INIT n CONFIG_INSMOD n CONFIG_LSMOD n CONFIG_MODINFO n CONFIG_MODPROBE n CONFIG_RMMOD n ''; }) (nftables.override { withCli = false; }) ]; # Packages that should be fully linked into /usr, # (not just their bin/* files). usrPackages = [ dbus firmware iwd kernel.modules terminfo # for xdp-forwarder spectrum-driver-tools ]; packagesSysroot = runCommand "packages-sysroot" { inherit packages; nativeBuildInputs = [ xorg.lndir ]; passAsFile = [ "packages" ]; } '' mkdir -p $out/usr/bin ln -st $out/usr/bin \ ${concatMapStringsSep " " (p: "${p}/bin/*") packages} for pkg in ${lib.escapeShellArgs usrPackages}; do lndir -ignorelinks -silent "$pkg" "$out/usr" done ''; nixosAllHardware = nixos ({ modulesPath, ... }: { boot.kernelPackages = linuxPackagesFor kernel; hardware.enableAllHardware = true; system.stateVersion = lib.trivial.release; }); in stdenvNoCC.mkDerivation { name = "spectrum-netvm"; src = lib.fileset.toSource { root = ../../..; fileset = lib.fileset.intersection src (lib.fileset.unions [ ./. ../../../lib/common.mk ../../../scripts/make-erofs.sh ../../../scripts/make-gpt.sh ../../../scripts/sfdisk-field.awk ]); }; sourceRoot = "source/vm/sys/net"; nativeBuildInputs = [ erofs-utils jq spectrum-build-tools s6-rc util-linux ]; env = { KERNEL = "${kernel}/${baseNameOf kernelTarget}"; PACKAGES = runCommand "packages" {} '' printf "%s\n/\n" ${packagesSysroot} >$out sed p ${writeClosure [ packagesSysroot] } >>$out ''; }; makeFlags = [ "prefix=$(out)" ]; dontInstall = true; enableParallelBuilding = true; __structuredAttrs = true; unsafeDiscardReferences = { out = true; }; dontFixup = true; passthru = { inherit firmware kernel packagesSysroot; }; meta = with lib; { license = licenses.eupl12; platforms = platforms.linux; }; } ) {}) ({ foot }: { inherit (foot) terminfo; })