-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{ | ||
llvmPackages, | ||
lib, | ||
fetchFromGitHub, | ||
writeShellScript, | ||
bash, | ||
meson, | ||
ninja, | ||
jq, | ||
bpftools, | ||
elfutils, | ||
zlib, | ||
zstd, | ||
pkg-config | ||
}: | ||
|
||
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; | ||
}; | ||
|
||
# Won't build with stable libbpf, so use the latest commit | ||
libbpf_src = fetchFromGitHub { | ||
owner = "libbpf"; | ||
repo = "libbpf"; | ||
inherit (versionInfo.libbpf) 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 | ||
''; | ||
fetchLibbpf = writeShellScript "fetch_libbpf" '' | ||
[ "$2" == '${libbpf_src.rev}' ] || exit 1 | ||
cd "$1" | ||
cp --no-preserve=mode,owner -r "${libbpf_src}/" ./libbpf | ||
mkdir -p ./libbpf/src/usr/include | ||
''; | ||
|
||
# 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 { | ||
pname = "scx_cscheds"; | ||
version = versionInfo.scx.version; | ||
|
||
src = fetchFromGitHub { | ||
owner = "sched-ext"; | ||
repo = "scx"; | ||
rev = "refs/tags/v${versionInfo.scx.version}"; | ||
inherit (versionInfo.scx) hash; | ||
}; | ||
|
||
postPatch = '' | ||
rm meson-scripts/fetch_bpftool meson-scripts/fetch_libbpf | ||
patchShebangs ./meson-scripts | ||
cp ${fetchBpftool} meson-scripts/fetch_bpftool | ||
cp ${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; | ||
"openrc" = false; | ||
# libbpf is already fetched as FOD | ||
#"libbpf_a" = true; | ||
# 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" | ||
"zerocallusedregs" | ||
]; | ||
|
||
preInstall = '' | ||
mkdir -p ${placeholder "dev"}/libbpf | ||
mkdir -p ${placeholder "dev"}/bpftool | ||
cp -r libbpf/* ${placeholder "dev"}/libbpf/ | ||
cp -r bpftool/* ${placeholder "dev"}/bpftool/ | ||
''; | ||
|
||
outputs = [ "bin" "dev" "out" ]; | ||
|
||
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. | ||
''; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ lib | ||
, llvmPackages | ||
, elfutils | ||
, zlib | ||
, pkg-config | ||
, rustPlatform | ||
, zstd | ||
, nix-update-script | ||
, scx-cscheds | ||
}: | ||
rustPlatform.buildRustPackage rec { | ||
pname = "scx_rustscheds"; | ||
inherit (scx-cscheds) version src; | ||
|
||
cargoHash = "sha256-bBDDNP+f9Ss6+IRFk3at+7+pDLMT6kOlTF1nnx6sqSE="; | ||
|
||
nativeBuildInputs = [ | ||
pkg-config | ||
llvmPackages.clang | ||
]; | ||
buildInputs = [ | ||
elfutils | ||
zlib | ||
zstd | ||
]; | ||
|
||
env = { | ||
LIBCLANG_PATH = "${lib.getLib llvmPackages.libclang}/lib"; | ||
BPF_CLANG = lib.getExe llvmPackages.clang; | ||
BPF_EXTRA_CFLAGS_PRE_INCL = "-I${scx-cscheds.dev}/libbpf/src/usr/include -I${scx-cscheds.dev}/libbpf/include/uapi"; | ||
RUSTFLAGS = "-C relocation-model=pic -C link-args=-lelf -C link-args=-lz -C link-args=-lzstd -L ${scx-cscheds.dev}/libbpf/src"; | ||
}; | ||
|
||
hardeningDisable = [ | ||
"stackprotector" | ||
"zerocallusedregs" | ||
]; | ||
|
||
# Enable this when default kernel in nixpkgs is 6.12+ | ||
doCheck = false; | ||
|
||
passthru.updateScript = nix-update-script {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"scx": { | ||
"version": "1.0.5", | ||
"hash": "sha256-nb2bzEanPPWTUhMmGw/8/bwOkdgNmwoZX2lMFq5Av5Q=" | ||
}, | ||
"bpftool": { | ||
"rev": "77a72987353fcae8ce330fd87d4c7afb7677a169", | ||
"hash": "sha256-pItTVewlXgB97AC/WH9rW9J/eYSe2ZdBkJaAgGnDeUU=" | ||
}, | ||
"libbpf": { | ||
"rev": "686f600bca59e107af4040d0838ca2b02c14ff50", | ||
"hash": "sha256-uIu57gFkPhBCq3RqKb6J4r5OB4X5/V9q8HqIafUc+Do=" | ||
} | ||
} |