diff --git a/nixos/doc/manual/release-notes/rl-2611.section.md b/nixos/doc/manual/release-notes/rl-2611.section.md index f993a9c3cbd6..cacb4a132c37 100644 --- a/nixos/doc/manual/release-notes/rl-2611.section.md +++ b/nixos/doc/manual/release-notes/rl-2611.section.md @@ -12,6 +12,8 @@ - [tranquil](https://tangled.org/tranquil.farm/tranquil-pds) is an ATProto PDS (personal data server) implementation in Rust. A featureful, spec conscious and community driven alternative to the Bluesky reference implementation PDS. Available as [services.tranquil-pds](#opt-services.tranquil-pds.enable). +- [scx_loader](https://github.com/sched-ext/scx-loader), a system daemon and DBus-based loader for sched_ext schedulers. `scxctl` is the command-line client for interacting with the loader, allowing users to switch schedulers, modes, and arguments dynamically. Available as [services.scx-loader](#opt-services.scx-loader.enable) + - [FlapAlerted](https://github.com/Kioubit/FlapAlerted), detects BGP flapping events and provides statistics based on BGP update messages. Available as [services.flap-alerted](#opt-services.flap-alerted.enable). ## Backward Incompatibilities {#sec-release-26.11-incompatibilities} diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 3ba8703f8555..6c5b1c80397f 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1483,6 +1483,7 @@ ./services/scheduling/cron.nix ./services/scheduling/fcron.nix ./services/scheduling/prefect.nix + ./services/scheduling/scx-loader.nix ./services/scheduling/scx.nix ./services/search/elasticsearch-curator.nix ./services/search/elasticsearch.nix diff --git a/nixos/modules/services/scheduling/scx-loader.nix b/nixos/modules/services/scheduling/scx-loader.nix new file mode 100644 index 000000000000..70c4df00c3bb --- /dev/null +++ b/nixos/modules/services/scheduling/scx-loader.nix @@ -0,0 +1,95 @@ +{ + lib, + pkgs, + config, + ... +}: +let + cfg = config.services.scx-loader; + settingsFormat = pkgs.formats.toml { }; + configFile = settingsFormat.generate "scx_loader.toml" ( + lib.filterAttrsRecursive (_: v: v != null) cfg.config + ); + + schedulers = builtins.concatMap ( + x: x.passthru.schedulers or (throw "Scheduler not found in package ${x.name}") + ) cfg.schedsPackages; +in +{ + options.services.scx-loader = { + enable = lib.mkEnableOption "SCX Loader service, a daemon to run schedulers from userspace using dbus. This requires kernel version 6.12 and later."; + + package = lib.mkPackageOption pkgs "scx-loader" { }; + + schedsPackages = lib.mkOption { + type = lib.types.listOf lib.types.package; + default = [ pkgs.scx.rustscheds ]; + defaultText = lib.literalExpression "[ pkgs.scx.rustscheds ]"; + example = lib.literalExpression "[ pkgs.scx.full ]"; + description = '' + `scx` package to use. Defaults to `scx.rustscheds`, which includes all currently by `scx_loader` supported schedulers. + ''; + }; + + config = lib.mkOption { + type = lib.types.submodule { + freeformType = settingsFormat.type; + + options = { + default_sched = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + example = "scx_bpfland"; + description = '' + Default scheduler that will be started automatically when `scx_loader` starts. + If not set or set to an empty string, `scx_loader` will not start any scheduler by default. + ''; + }; + }; + }; + default = { }; + description = '' + Configuration for `scx_loader`. + + See for the full list of options. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = lib.versionAtLeast config.boot.kernelPackages.kernel.version "6.12"; + message = "SCX is only supported on kernel version 6.12 and above."; + } + { + assertion = !config.services.scx.enable; + message = "services.scx and services.scx_loader cannot be enabled simultaneously. Please enable only one of them."; + } + { + assertion = + cfg.config.default_sched == null || lib.elem cfg.config.default_sched ([ "" ] ++ schedulers); + message = '' + Invalid default scheduler: ${cfg.config.default_sched}. It must be one of: ${lib.concatStringsSep ", " schedulers}. + ''; + } + ]; + + environment.systemPackages = [ cfg.package ] ++ cfg.schedsPackages; + systemd.packages = [ cfg.package ]; + services.dbus.packages = [ cfg.package ]; + + security.polkit.enable = true; + + systemd.services.scx_loader = { + path = cfg.schedsPackages; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + TemporaryFileSystem = [ "/etc" ]; + BindReadOnlyPaths = [ "${configFile.outPath}:/etc/scx_loader.toml" ]; + }; + }; + }; + + meta.maintainers = with lib.maintainers; [ ccicnce113424 ]; +}