summary refs log tree commit diff
path: root/nixos/modules/programs
diff options
context:
space:
mode:
authorThiago Kenji Okada <thiagokokada@gmail.com>2023-10-04 22:09:54 +0100
committerThiago Kenji Okada <thiagokokada@gmail.com>2023-10-05 15:26:47 +0100
commit63fce4ce48e3706db40010ce3b0a432c70caa1ab (patch)
treedd8b52865639da41354f9bf86c24c53c690a3f6f /nixos/modules/programs
parent2f4249e4665e6f08277afd371aaf6da8973e8602 (diff)
downloadnixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.tar
nixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.tar.gz
nixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.tar.bz2
nixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.tar.lz
nixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.tar.xz
nixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.tar.zst
nixpkgs-63fce4ce48e3706db40010ce3b0a432c70caa1ab.zip
nixos/sway: add enableRealtime option
This option wraps the `sway` binary to allow it to request realtime
scheduling (SCHED_RR). This allow for possible lower latency, specially
when the system is under high load.

Available since Sway 1.8. See:
- https://github.com/swaywm/sway/pull/6994
- https://github.com/swaywm/sway/releases/tag/1.8
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r--nixos/modules/programs/wayland/sway.nix13
1 files changed, 13 insertions, 0 deletions
diff --git a/nixos/modules/programs/wayland/sway.nix b/nixos/modules/programs/wayland/sway.nix
index 698d9c2b46c..de739faabee 100644
--- a/nixos/modules/programs/wayland/sway.nix
+++ b/nixos/modules/programs/wayland/sway.nix
@@ -42,6 +42,11 @@ in {
       <https://github.com/swaywm/sway/wiki> and
       "man 5 sway" for more information'');
 
+    enableRealtime = mkEnableOption (lib.mdDoc ''
+      add CAP_SYS_NICE capability on `sway` binary for realtime scheduling
+      privileges. This may improve latency and reduce stuttering, specially in
+      high load scenarios'') // { default = true; };
+
     package = mkOption {
       type = with types; nullOr package;
       default = defaultSwayPackage;
@@ -149,6 +154,14 @@ in {
             "sway/config".source = mkOptionDefault "${cfg.package}/etc/sway/config";
           };
         };
+        security.wrappers = mkIf (cfg.enableRealtime && cfg.package != null) {
+          sway = {
+            owner = "root";
+            group = "root";
+            source = "${cfg.package}/bin/sway";
+            capabilities = "cap_sys_nice+ep";
+          };
+        };
         # To make a Sway session available if a display manager like SDDM is enabled:
         services.xserver.displayManager.sessionPackages = optionals (cfg.package != null) [ cfg.package ]; }
       (import ./wayland-session.nix { inherit lib pkgs; })