depot/pkgs/os-specific/linux/scx/scx_cscheds.nix
Luke Granger-Brown 57725ef3ec Squashed 'third_party/nixpkgs/' content from commit 76612b17c0ce
git-subtree-dir: third_party/nixpkgs
git-subtree-split: 76612b17c0ce71689921ca12d9ffdc9c23ce40b2
2024-11-10 23:59:47 +00:00

109 lines
2.5 KiB
Nix

{
stdenv,
lib,
mkScxScheduler,
fetchFromGitHub,
writeShellScript,
bash,
meson,
ninja,
jq,
bpftools,
elfutils,
zlib,
libbpf,
}:
let
versionInfo = lib.importJSON ./version.json;
# scx needs a specific commit of bpftool
# can be found in meson.build of scx src
# grep 'bpftool_commit =' ./meson.build
bpftools_src = fetchFromGitHub {
owner = "libbpf";
repo = "bpftool";
inherit (versionInfo.bpftool) rev hash;
fetchSubmodules = true;
};
# scx needs a specific commit of bpftool
# this imitates the fetch_bpftool script in src/meson-scripts
fetchBpftool = writeShellScript "fetch_bpftool" ''
[ "$2" == '${bpftools_src.rev}' ] || exit 1
cd "$1"
cp --no-preserve=mode,owner -r "${bpftools_src}/" ./bpftool
'';
# 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} "$@"
'';
# Won't build with stable libbpf, so use the latest commit
libbpf-git = libbpf.overrideAttrs (oldAttrs: {
src = fetchFromGitHub {
owner = "libbpf";
repo = "libbpf";
inherit (versionInfo.libbpf) rev hash;
fetchSubmodules = true;
};
});
in
mkScxScheduler "c" {
schedulerName = "scx_cscheds";
postPatch = ''
rm meson-scripts/fetch_bpftool
patchShebangs ./meson-scripts
cp ${fetchBpftool} meson-scripts/fetch_bpftool
substituteInPlace meson.build \
--replace-fail '[build_bpftool' "['${misbehaviorBash}', build_bpftool"
'';
nativeBuildInputs = [
meson
ninja
jq
] ++ bpftools.buildInputs ++ bpftools.nativeBuildInputs;
buildInputs = [
elfutils
zlib
libbpf-git
];
mesonFlags = [
(lib.mapAttrsToList lib.mesonEnable {
# systemd unit is implemented in the nixos module
# upstream systemd files are a hassle to patch
"systemd" = false;
"openrc" = false;
# libbpf is already fetched as FOD
"libbpf_a" = false;
# not for nix
"libalpm" = false;
})
(lib.mapAttrsToList lib.mesonBool {
# needed libs are already fetched as FOD
"offline" = true;
# rust based schedulers are built seperately
"enable_rust" = false;
})
];
hardeningDisable = [
"stackprotector"
];
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.
'';
};
}