mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-08 14:03:29 +00:00
137 lines
3.5 KiB
Nix
137 lines
3.5 KiB
Nix
{
|
|
lib,
|
|
llvmPackages,
|
|
fetchFromGitHub,
|
|
writeShellScript,
|
|
bash,
|
|
meson,
|
|
ninja,
|
|
jq,
|
|
pkg-config,
|
|
bpftools,
|
|
elfutils,
|
|
zlib,
|
|
zstd,
|
|
scx-common,
|
|
}:
|
|
|
|
let
|
|
# Fixes a bug with the meson build script where it specifies
|
|
# /bin/bash twice in the script
|
|
misbehaviorBash = writeShellScript "bash" ''
|
|
shift 1
|
|
exec ${lib.getExe bash} "$@"
|
|
'';
|
|
|
|
in
|
|
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.build \
|
|
--replace-fail '[build_bpftool' "['${misbehaviorBash}', build_bpftool"
|
|
'';
|
|
|
|
nativeBuildInputs = [
|
|
meson
|
|
ninja
|
|
jq
|
|
pkg-config
|
|
zstd
|
|
] ++ bpftools.buildInputs ++ bpftools.nativeBuildInputs;
|
|
|
|
buildInputs = [
|
|
elfutils
|
|
zlib
|
|
];
|
|
|
|
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;
|
|
"libalpm" = false;
|
|
})
|
|
(lib.mapAttrsToList lib.mesonBool {
|
|
# needed libs are already fetched as FOD
|
|
"offline" = true;
|
|
# rust based schedulers are built seperately
|
|
"enable_rust" = false;
|
|
})
|
|
# Clang to use when compiling .bpf.c
|
|
(lib.mesonOption "bpf_clang" (lib.getExe llvmPackages.clang))
|
|
];
|
|
|
|
hardeningDisable = [
|
|
"stackprotector"
|
|
"zerocallusedregs"
|
|
];
|
|
|
|
# We copy the compiled header files to the dev output
|
|
# These are needed for the rust schedulers
|
|
preInstall = ''
|
|
mkdir -p ${placeholder "dev"}/libbpf ${placeholder "dev"}/bpftool
|
|
cp -r libbpf/* ${placeholder "dev"}/libbpf/
|
|
cp -r bpftool/* ${placeholder "dev"}/bpftool/
|
|
'';
|
|
|
|
outputs = [
|
|
"bin"
|
|
"dev"
|
|
"out"
|
|
];
|
|
|
|
# Enable this when default kernel in nixpkgs is 6.12+
|
|
doCheck = false;
|
|
|
|
meta = scx-common.meta // {
|
|
description = "Sched-ext C userspace schedulers";
|
|
longDescription = ''
|
|
This includes C based schedulers such as scx_central, scx_flatcg,
|
|
scx_nest, scx_pair, scx_qmap, scx_simple, scx_userland.
|
|
|
|
::: {.note}
|
|
Sched-ext schedulers are only available on kernels version 6.12 or later.
|
|
It is recommended to use the latest kernel for the best compatibility.
|
|
:::
|
|
'';
|
|
};
|
|
})
|