Loading pkgs/os-specific/linux/scx/default.nix +4 −35 Original line number Diff line number Diff line { lib, callPackage, fetchFromGitHub, }: let scx-common = rec { versionInfo = lib.importJSON ./version.json; inherit (versionInfo.scx) version; src = fetchFromGitHub { owner = "sched-ext"; repo = "scx"; tag = "v${versionInfo.scx.version}"; inherit (versionInfo.scx) hash; }; meta = { homepage = "https://github.com/sched-ext/scx"; changelog = "https://github.com/sched-ext/scx/releases/tag/v${versionInfo.scx.version}"; license = lib.licenses.gpl2Only; platforms = lib.platforms.linux; badPlatforms = [ "aarch64-linux" ]; maintainers = with lib.maintainers; [ johnrtitor Gliczy ]; }; }; schedulers = lib.mergeAttrsList [ { cscheds = import ./scx_cscheds.nix; } { rustscheds = import ./scx_rustscheds.nix; } { full = import ./scx_full.nix; } ]; in (lib.mapAttrs (name: scheduler: callPackage scheduler { inherit scx-common; }) schedulers) // { inherit scx-common; lib.mapAttrs (name: scheduler: callPackage scheduler { }) { cscheds = import ./scx_cscheds.nix; rustscheds = import ./scx_rustscheds.nix; full = import ./scx_full.nix; } pkgs/os-specific/linux/scx/scx_cscheds.nix +18 −79 Original line number Diff line number Diff line { lib, llvmPackages, fetchFromGitHub, writeShellScript, bash, meson, ninja, jq, libbpf, pkg-config, bpftools, elfutils, zlib, zstd, scx-common, protobuf, scx, libseccomp, }: llvmPackages.stdenv.mkDerivation (finalAttrs: { llvmPackages.stdenv.mkDerivation { 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 ''; inherit (scx.rustscheds) version src; 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 Loading @@ -78,37 +32,21 @@ 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 // { passthru = { inherit (scx.rustscheds.passthru) tests; }; meta = scx.rustscheds.meta // { description = "Sched-ext C userspace schedulers"; longDescription = '' This includes C based schedulers such as scx_central, scx_flatcg, Loading @@ -119,5 +57,6 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: { It is recommended to use the latest kernel for the best compatibility. ::: ''; homepage = "https://github.com/sched-ext/scx/tree/main/scheds/c"; }; }) } pkgs/os-specific/linux/scx/scx_full.nix +2 −8 Original line number Diff line number Diff line { lib, stdenv, scx-common, scx, nixosTests, }: 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; passthru.updateScript.command = ./update.sh; meta = oldAttrs.meta // { description = "Sched-ext C and Rust userspace schedulers"; longDescription = '' Loading @@ -27,5 +20,6 @@ scx.cscheds.overrideAttrs (oldAttrs: { It is recommended to use the latest kernel for the best compatibility. ::: ''; homepage = "https://github.com/sched-ext/scx"; }; }) pkgs/os-specific/linux/scx/scx_rustscheds.nix +28 −7 Original line number Diff line number Diff line Loading @@ -6,15 +6,24 @@ elfutils, zlib, zstd, scx-common, fetchFromGitHub, protobuf, libseccomp, nix-update-script, nixosTests, }: rustPlatform.buildRustPackage { rustPlatform.buildRustPackage (finalAttrs: { pname = "scx_rustscheds"; inherit (scx-common) version src; version = "1.0.17"; inherit (scx-common.versionInfo.scx) cargoHash; src = fetchFromGitHub { owner = "sched-ext"; repo = "scx"; tag = "v${finalAttrs.version}"; hash = "sha256-UhFHT8cSrdjhSqjj4qFzn5UvfPOLPwrBh1ytL2gFhzU="; }; cargoHash = "sha256-yQM2zx1IzGjegwLK4epsluWl8m5RSP3jB00Lpd8+TLE="; nativeBuildInputs = [ pkg-config Loading @@ -39,7 +48,6 @@ rustPlatform.buildRustPackage { }; hardeningDisable = [ "stackprotector" "zerocallusedregs" ]; Loading @@ -53,7 +61,10 @@ rustPlatform.buildRustPackage { "--skip=proc_data::tests::test_thread_operations" ]; meta = scx-common.meta // { passthru.tests.basic = nixosTests.scx; passthru.updateScript = nix-update-script { }; meta = { description = "Sched-ext Rust userspace schedulers"; longDescription = '' This includes Rust based schedulers such as Loading @@ -64,5 +75,15 @@ rustPlatform.buildRustPackage { It is recommended to use the latest kernel for the best compatibility. ::: ''; homepage = "https://github.com/sched-ext/scx/tree/main/scheds/rust"; changelog = "https://github.com/sched-ext/scx/releases/tag/v${finalAttrs.version}"; license = lib.licenses.gpl2Only; platforms = lib.platforms.linux; badPlatforms = [ "aarch64-linux" ]; maintainers = with lib.maintainers; [ johnrtitor Gliczy ]; }; } }) pkgs/os-specific/linux/scx/update.shdeleted 100755 → 0 +0 −57 Original line number Diff line number Diff line #! /usr/bin/env nix-shell #! nix-shell -i bash -p coreutils moreutils curl jq nix-prefetch-git cargo gnugrep gawk nix # shellcheck shell=bash # You must run it from the root directory of a nixpkgs repo checkout set -euo pipefail versionJson="$(realpath "./pkgs/os-specific/linux/scx/version.json")" nixFolder="$(dirname "$versionJson")" localVer=$(jq -r .scx.version <$versionJson) latestVer=$(curl -s https://api.github.com/repos/sched-ext/scx/releases/latest | jq -r .tag_name | sed 's/v//g') if [ "$localVer" == "$latestVer" ]; then exit 0 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" \ "$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 echo "Failed to get cargoHash, please update it manually" exit 0 fi jq \ --arg cargoHash "$cargoHash" \ ".scx.cargoHash = \$cargoHash" \ "$versionJson" | sponge $versionJson Loading
pkgs/os-specific/linux/scx/default.nix +4 −35 Original line number Diff line number Diff line { lib, callPackage, fetchFromGitHub, }: let scx-common = rec { versionInfo = lib.importJSON ./version.json; inherit (versionInfo.scx) version; src = fetchFromGitHub { owner = "sched-ext"; repo = "scx"; tag = "v${versionInfo.scx.version}"; inherit (versionInfo.scx) hash; }; meta = { homepage = "https://github.com/sched-ext/scx"; changelog = "https://github.com/sched-ext/scx/releases/tag/v${versionInfo.scx.version}"; license = lib.licenses.gpl2Only; platforms = lib.platforms.linux; badPlatforms = [ "aarch64-linux" ]; maintainers = with lib.maintainers; [ johnrtitor Gliczy ]; }; }; schedulers = lib.mergeAttrsList [ { cscheds = import ./scx_cscheds.nix; } { rustscheds = import ./scx_rustscheds.nix; } { full = import ./scx_full.nix; } ]; in (lib.mapAttrs (name: scheduler: callPackage scheduler { inherit scx-common; }) schedulers) // { inherit scx-common; lib.mapAttrs (name: scheduler: callPackage scheduler { }) { cscheds = import ./scx_cscheds.nix; rustscheds = import ./scx_rustscheds.nix; full = import ./scx_full.nix; }
pkgs/os-specific/linux/scx/scx_cscheds.nix +18 −79 Original line number Diff line number Diff line { lib, llvmPackages, fetchFromGitHub, writeShellScript, bash, meson, ninja, jq, libbpf, pkg-config, bpftools, elfutils, zlib, zstd, scx-common, protobuf, scx, libseccomp, }: llvmPackages.stdenv.mkDerivation (finalAttrs: { llvmPackages.stdenv.mkDerivation { 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 ''; inherit (scx.rustscheds) version src; 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 Loading @@ -78,37 +32,21 @@ 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 // { passthru = { inherit (scx.rustscheds.passthru) tests; }; meta = scx.rustscheds.meta // { description = "Sched-ext C userspace schedulers"; longDescription = '' This includes C based schedulers such as scx_central, scx_flatcg, Loading @@ -119,5 +57,6 @@ llvmPackages.stdenv.mkDerivation (finalAttrs: { It is recommended to use the latest kernel for the best compatibility. ::: ''; homepage = "https://github.com/sched-ext/scx/tree/main/scheds/c"; }; }) }
pkgs/os-specific/linux/scx/scx_full.nix +2 −8 Original line number Diff line number Diff line { lib, stdenv, scx-common, scx, nixosTests, }: 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; passthru.updateScript.command = ./update.sh; meta = oldAttrs.meta // { description = "Sched-ext C and Rust userspace schedulers"; longDescription = '' Loading @@ -27,5 +20,6 @@ scx.cscheds.overrideAttrs (oldAttrs: { It is recommended to use the latest kernel for the best compatibility. ::: ''; homepage = "https://github.com/sched-ext/scx"; }; })
pkgs/os-specific/linux/scx/scx_rustscheds.nix +28 −7 Original line number Diff line number Diff line Loading @@ -6,15 +6,24 @@ elfutils, zlib, zstd, scx-common, fetchFromGitHub, protobuf, libseccomp, nix-update-script, nixosTests, }: rustPlatform.buildRustPackage { rustPlatform.buildRustPackage (finalAttrs: { pname = "scx_rustscheds"; inherit (scx-common) version src; version = "1.0.17"; inherit (scx-common.versionInfo.scx) cargoHash; src = fetchFromGitHub { owner = "sched-ext"; repo = "scx"; tag = "v${finalAttrs.version}"; hash = "sha256-UhFHT8cSrdjhSqjj4qFzn5UvfPOLPwrBh1ytL2gFhzU="; }; cargoHash = "sha256-yQM2zx1IzGjegwLK4epsluWl8m5RSP3jB00Lpd8+TLE="; nativeBuildInputs = [ pkg-config Loading @@ -39,7 +48,6 @@ rustPlatform.buildRustPackage { }; hardeningDisable = [ "stackprotector" "zerocallusedregs" ]; Loading @@ -53,7 +61,10 @@ rustPlatform.buildRustPackage { "--skip=proc_data::tests::test_thread_operations" ]; meta = scx-common.meta // { passthru.tests.basic = nixosTests.scx; passthru.updateScript = nix-update-script { }; meta = { description = "Sched-ext Rust userspace schedulers"; longDescription = '' This includes Rust based schedulers such as Loading @@ -64,5 +75,15 @@ rustPlatform.buildRustPackage { It is recommended to use the latest kernel for the best compatibility. ::: ''; homepage = "https://github.com/sched-ext/scx/tree/main/scheds/rust"; changelog = "https://github.com/sched-ext/scx/releases/tag/v${finalAttrs.version}"; license = lib.licenses.gpl2Only; platforms = lib.platforms.linux; badPlatforms = [ "aarch64-linux" ]; maintainers = with lib.maintainers; [ johnrtitor Gliczy ]; }; } })
pkgs/os-specific/linux/scx/update.shdeleted 100755 → 0 +0 −57 Original line number Diff line number Diff line #! /usr/bin/env nix-shell #! nix-shell -i bash -p coreutils moreutils curl jq nix-prefetch-git cargo gnugrep gawk nix # shellcheck shell=bash # You must run it from the root directory of a nixpkgs repo checkout set -euo pipefail versionJson="$(realpath "./pkgs/os-specific/linux/scx/version.json")" nixFolder="$(dirname "$versionJson")" localVer=$(jq -r .scx.version <$versionJson) latestVer=$(curl -s https://api.github.com/repos/sched-ext/scx/releases/latest | jq -r .tag_name | sed 's/v//g') if [ "$localVer" == "$latestVer" ]; then exit 0 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" \ "$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 echo "Failed to get cargoHash, please update it manually" exit 0 fi jq \ --arg cargoHash "$cargoHash" \ ".scx.cargoHash = \$cargoHash" \ "$versionJson" | sponge $versionJson