patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 889e5ec477d592dc08ca1261e45fc4d9463eadb0 4063 bytes (raw)
name: vm/sys/net/default.nix 	 # note: path name is non-authoritative(*)

  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
 
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021-2023 Alyssa Ross <hi@alyssa.is>

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, kmod, linux_latest, mdevd, nftables
, s6, s6-linux-init, xdp-tools, spectrum-driver-tools, iwd
}:

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
      stdenvNoCC.hostPlatform.linux-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 kernel.modules terminfo iwd

    # 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, ... }: {
    imports = [ (modulesPath + "/profiles/all-hardware.nix") ];

    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; })

debug log:

solving 889e5ec ...
found 889e5ec in https://inbox.spectrum-os.org/spectrum-devel/20251129194404.37773-6-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251129181514.20296-6-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251128223038.97536-4-yureka@cyberchaos.dev/
found f4e51dd in https://inbox.spectrum-os.org/spectrum-devel/20251128223038.97536-3-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251129194404.37773-5-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251129181514.20296-5-yureka@cyberchaos.dev/
found ae7fdc5 in https://spectrum-os.org/git/spectrum
preparing index
index prepared:
100644 ae7fdc5521d6b16327a4608cde7e4f4595f7058f	vm/sys/net/default.nix

applying [1/2] https://inbox.spectrum-os.org/spectrum-devel/20251128223038.97536-3-yureka@cyberchaos.dev/
diff --git a/vm/sys/net/default.nix b/vm/sys/net/default.nix
index ae7fdc5..f4e51dd 100644

Checking patch vm/sys/net/default.nix...
Applied patch vm/sys/net/default.nix cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20251129194404.37773-5-yureka@cyberchaos.dev/ for f4e51dd
skipping https://inbox.spectrum-os.org/spectrum-devel/20251129181514.20296-5-yureka@cyberchaos.dev/ for f4e51dd
index at:
100644 f4e51dd1e8f2463f8ef268f844db916fc67d8220	vm/sys/net/default.nix

applying [2/2] https://inbox.spectrum-os.org/spectrum-devel/20251129194404.37773-6-yureka@cyberchaos.dev/
diff --git a/vm/sys/net/default.nix b/vm/sys/net/default.nix
index f4e51dd..889e5ec 100644

Checking patch vm/sys/net/default.nix...
Applied patch vm/sys/net/default.nix cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20251129181514.20296-6-yureka@cyberchaos.dev/ for 889e5ec
skipping https://inbox.spectrum-os.org/spectrum-devel/20251128223038.97536-4-yureka@cyberchaos.dev/ for 889e5ec
index at:
100644 889e5ec477d592dc08ca1261e45fc4d9463eadb0	vm/sys/net/default.nix

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).