From 68f2d23b9a47ad03c7ded184e1cedf6353be1903 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sun, 19 Oct 2025 18:45:14 +0530 Subject: [PATCH] scx.cscheds: switch to make packaging Upstream deprecated meson builds. This also switches libbpf and bpftool dependencies to nixpkgs provided ones. Please report if this causes any issues. --- pkgs/os-specific/linux/scx/scx_cscheds.nix | 82 ++----------------- pkgs/os-specific/linux/scx/scx_full.nix | 2 +- pkgs/os-specific/linux/scx/scx_rustscheds.nix | 1 - pkgs/os-specific/linux/scx/update.sh | 20 +---- pkgs/os-specific/linux/scx/version.json | 8 -- 5 files changed, 10 insertions(+), 103 deletions(-) diff --git a/pkgs/os-specific/linux/scx/scx_cscheds.nix b/pkgs/os-specific/linux/scx/scx_cscheds.nix index a487493bad5b..8b59bcb9aab5 100644 --- a/pkgs/os-specific/linux/scx/scx_cscheds.nix +++ b/pkgs/os-specific/linux/scx/scx_cscheds.nix @@ -1,19 +1,12 @@ { - lib, llvmPackages, - fetchFromGitHub, - writeShellScript, - bash, - meson, - ninja, - jq, + libbpf, pkg-config, bpftools, elfutils, zlib, zstd, scx-common, - protobuf, libseccomp, }: @@ -21,56 +14,17 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: { pname = "scx_cscheds"; inherit (scx-common) version src; - # scx needs specific commits of bpftool and libbpf - # can be found in meson.build of scx src - # grep 'bpftool_commit =' ./meson.build - bpftools_src = fetchFromGitHub { - owner = "libbpf"; - repo = "bpftool"; - inherit (scx-common.versionInfo.bpftool) rev hash; - fetchSubmodules = true; - }; - # grep 'libbpf_commit = ' ./meson.build - libbpf_src = fetchFromGitHub { - owner = "libbpf"; - repo = "libbpf"; - inherit (scx-common.versionInfo.libbpf) rev hash; - fetchSubmodules = true; - }; - - # this imitates the fetch_bpftool and fetch_libbpf script in src/meson-scripts - fetchBpftool = writeShellScript "fetch_bpftool" '' - [ "$2" == '${finalAttrs.bpftools_src.rev}' ] || exit 1 - cd "$1" - cp --no-preserve=mode,owner -r "${finalAttrs.bpftools_src}/" ./bpftool - ''; - fetchLibbpf = writeShellScript "fetch_libbpf" '' - [ "$2" == '${finalAttrs.libbpf_src.rev}' ] || exit 1 - cd "$1" - cp --no-preserve=mode,owner -r "${finalAttrs.libbpf_src}/" ./libbpf - mkdir -p ./libbpf/src/usr/include - ''; - postPatch = '' - rm meson-scripts/fetch_bpftool meson-scripts/fetch_libbpf - patchShebangs ./meson-scripts - cp ${finalAttrs.fetchBpftool} meson-scripts/fetch_bpftool - cp ${finalAttrs.fetchLibbpf} meson-scripts/fetch_libbpf - substituteInPlace ./meson-scripts/build_bpftool \ - --replace-fail '/bin/bash' '${lib.getExe bash}' + substituteInPlace ./scheds/c/Makefile \ + --replace-fail '/usr/local' '${placeholder "out"}' ''; nativeBuildInputs = [ - meson - ninja - jq pkg-config zstd - protobuf - llvmPackages.libllvm - ] - ++ bpftools.buildInputs - ++ bpftools.nativeBuildInputs; + bpftools + libbpf + ]; buildInputs = [ elfutils @@ -78,34 +32,14 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: { libseccomp ]; - mesonFlags = [ - (lib.mapAttrsToList lib.mesonEnable { - # systemd unit is implemented in the nixos module - # upstream systemd files are a hassle to patch - "systemd" = false; - # not for nix - "openrc" = false; - }) - (lib.mapAttrsToList lib.mesonBool { - # needed libs are already fetched as FOD - "offline" = true; - # rust based schedulers are built separately - "enable_rust" = false; - }) - # Clang to use when compiling .bpf.c - (lib.mesonOption "bpf_clang" (lib.getExe llvmPackages.clang)) + makeFlags = [ + "PREFIX=${placeholder "out"}" ]; hardeningDisable = [ - "stackprotector" "zerocallusedregs" ]; - outputs = [ - "bin" - "out" - ]; - doCheck = true; meta = scx-common.meta // { diff --git a/pkgs/os-specific/linux/scx/scx_full.nix b/pkgs/os-specific/linux/scx/scx_full.nix index f47e92e8b96e..c7a2a86e5329 100644 --- a/pkgs/os-specific/linux/scx/scx_full.nix +++ b/pkgs/os-specific/linux/scx/scx_full.nix @@ -8,7 +8,7 @@ scx.cscheds.overrideAttrs (oldAttrs: { pname = "scx_full"; postInstall = (oldAttrs.postInstall or "") + '' - cp ${scx.rustscheds}/bin/* ${placeholder "bin"}/bin/ + cp ${lib.getBin scx.rustscheds}/bin/* ${placeholder "out"}/bin/ ''; passthru.tests.basic = nixosTests.scx; diff --git a/pkgs/os-specific/linux/scx/scx_rustscheds.nix b/pkgs/os-specific/linux/scx/scx_rustscheds.nix index c43bfee59861..3aca28e3812f 100644 --- a/pkgs/os-specific/linux/scx/scx_rustscheds.nix +++ b/pkgs/os-specific/linux/scx/scx_rustscheds.nix @@ -39,7 +39,6 @@ rustPlatform.buildRustPackage { }; hardeningDisable = [ - "stackprotector" "zerocallusedregs" ]; diff --git a/pkgs/os-specific/linux/scx/update.sh b/pkgs/os-specific/linux/scx/update.sh index dd516aebaefd..f76c4c4fa78f 100755 --- a/pkgs/os-specific/linux/scx/update.sh +++ b/pkgs/os-specific/linux/scx/update.sh @@ -18,32 +18,14 @@ fi latestHash=$(nix-prefetch-git https://github.com/sched-ext/scx.git --rev refs/tags/v$latestVer --quiet | jq -r .hash) -tmp=$(mktemp -d) -trap 'rm -rf -- "${tmp}"' EXIT - -git clone --depth 1 --branch "v$latestVer" https://github.com/sched-ext/scx.git "$tmp/scx" - -pushd "$tmp/scx" - -bpftoolRev=$(grep 'bpftool_commit =' ./meson.build | awk -F"'" '{print $2}') -bpftoolHash=$(nix-prefetch-git https://github.com/libbpf/bpftool.git --rev $bpftoolRev --fetch-submodules --quiet | jq -r .hash) - -libbpfRev=$(grep 'libbpf_commit =' ./meson.build | awk -F"'" '{print $2}') -libbpfHash=$(nix-prefetch-git https://github.com/libbpf/libbpf.git --rev $libbpfRev --fetch-submodules --quiet | jq -r .hash) - jq \ --arg latestVer "$latestVer" --arg latestHash "$latestHash" \ - --arg bpftoolRev "$bpftoolRev" --arg bpftoolHash "$bpftoolHash" \ - --arg libbpfRev "$libbpfRev" --arg libbpfHash "$libbpfHash" \ - ".scx.version = \$latestVer | .scx.hash = \$latestHash |\ - .bpftool.rev = \$bpftoolRev | .bpftool.hash = \$bpftoolHash |\ - .libbpf.rev = \$libbpfRev | .libbpf.hash = \$libbpfHash" \ + ".scx.version = \$latestVer | .scx.hash = \$latestHash" \ "$versionJson" | sponge $versionJson echo "scx: $localVer -> $latestVer" echo "Updating cargoHash. This may take a while..." -popd cargoHash=$((nix-build --attr scx.rustscheds 2>&1 || true) | awk '/got/{print $2}') if [ -z "$cargoHash" ]; then diff --git a/pkgs/os-specific/linux/scx/version.json b/pkgs/os-specific/linux/scx/version.json index f655beec2bb9..f9334629755c 100644 --- a/pkgs/os-specific/linux/scx/version.json +++ b/pkgs/os-specific/linux/scx/version.json @@ -3,13 +3,5 @@ "version": "1.0.17", "hash": "sha256-UhFHT8cSrdjhSqjj4qFzn5UvfPOLPwrBh1ytL2gFhzU=", "cargoHash": "sha256-yQM2zx1IzGjegwLK4epsluWl8m5RSP3jB00Lpd8+TLE=" - }, - "bpftool": { - "rev": "183e7010387d1fc9f08051426e9a9fbd5f8d409e", - "hash": "sha256-ZZly6csVWOmtLmld1fhSDUqyRgZx2gSMGXTaSASGv7c=" - }, - "libbpf": { - "rev": "b4fa3e39a77fd65574fb5f899486795fc3d89bd9", - "hash": "sha256-wlymVgcLlGCUOC92CkYU6QZZnqx8nidSfhr1pTiS8aM=" } }