about summary refs log tree commit diff
path: root/pkgs/applications/window-managers
diff options
context:
space:
mode:
authorAdam Joseph <54836058+a-m-joseph@users.noreply.github.com>2022-03-06 12:39:31 +0000
committerGitHub <noreply@github.com>2022-03-06 13:39:31 +0100
commitc7a7acb034f090a315d79f05475327919a501cfd (patch)
tree8fbcb2c494cf9c35585419e099c8f34b45a35e04 /pkgs/applications/window-managers
parenta943a5d9da64f293b12c9171a2a8bfb8fef46386 (diff)
downloadnixlib-c7a7acb034f090a315d79f05475327919a501cfd.tar
nixlib-c7a7acb034f090a315d79f05475327919a501cfd.tar.gz
nixlib-c7a7acb034f090a315d79f05475327919a501cfd.tar.bz2
nixlib-c7a7acb034f090a315d79f05475327919a501cfd.tar.lz
nixlib-c7a7acb034f090a315d79f05475327919a501cfd.tar.xz
nixlib-c7a7acb034f090a315d79f05475327919a501cfd.tar.zst
nixlib-c7a7acb034f090a315d79f05475327919a501cfd.zip
sway: respect systemdSupport and dbusSupport (#160972)
Sway can be compiled with or without systemd(-logind) and dbus.  This
commit exposes that support via the global systemdSupport and
dbusSupport arguments, which are understood by many other nixpkgs
expressions and can be set globally in ~/.config/nixpkgs/config.nix.

This commit also adds a third argument, trayEnabled, which allows to
disable sway's tray.  The tray requires dbusSupport and
systemdSupport.

Reviewers of this commit asked for potential use cases.  There are
many of them; a very non-exhaustive list includes:

* Use of nixpkgs on operating systems which systemd does not support,
  such as MacOS/Darwin, FreeBSD, OpenBSD, or Alpine Linux.

* Use of nixpkgs on *-musl platforms, which systemd does not
  officially support (out-of-tree patches to support musl exist for a
  few systemd versions).

* Use of sway in situations where dbus is inappropriate, such as
  sway's "kiosk mode".

* High-security environments, where the additional attack surface
  exposed by dbus outweighs any features it may offer.

This is a very non-exhaustive list.
Diffstat (limited to 'pkgs/applications/window-managers')
-rw-r--r--pkgs/applications/window-managers/sway/default.nix23
-rw-r--r--pkgs/applications/window-managers/sway/wrapper.nix3
2 files changed, 20 insertions, 6 deletions
diff --git a/pkgs/applications/window-managers/sway/default.nix b/pkgs/applications/window-managers/sway/default.nix
index 194525dcffb5..9ea6c1650ee0 100644
--- a/pkgs/applications/window-managers/sway/default.nix
+++ b/pkgs/applications/window-managers/sway/default.nix
@@ -1,6 +1,6 @@
 { lib, stdenv, fetchFromGitHub, substituteAll, swaybg
 , meson, ninja, pkg-config, wayland-scanner, scdoc
-, wayland, libxkbcommon, pcre, json_c, dbus, libevdev
+, wayland, libxkbcommon, pcre, json_c, libevdev
 , pango, cairo, libinput, libcap, pam, gdk-pixbuf, librsvg
 , wlroots, wayland-protocols, libdrm
 , nixosTests
@@ -8,8 +8,19 @@
 , isNixOS ? false
 
 , enableXWayland ? true
+, systemdSupport ? stdenv.isLinux
+, dbusSupport ? true
+, dbus
+, trayEnabled ? dbusSupport
 }:
 
+# The "sd-bus-provider" meson option does not include a "none" option,
+# but it is silently ignored iff "-Dtray=disabled".  We use "basu"
+# (which is not in nixpkgs) instead of "none" to alert us if this
+# changes: https://github.com/swaywm/sway/issues/6843#issuecomment-1047288761
+assert trayEnabled -> systemdSupport && dbusSupport;
+let sd-bus-provider = if systemdSupport then "libsystemd" else "basu"; in
+
 stdenv.mkDerivation rec {
   pname = "sway-unwrapped";
   version = "1.7";
@@ -47,16 +58,18 @@ stdenv.mkDerivation rec {
   ];
 
   buildInputs = [
-    wayland libxkbcommon pcre json_c dbus libevdev
+    wayland libxkbcommon pcre json_c libevdev
     pango cairo libinput libcap pam gdk-pixbuf librsvg
     wayland-protocols libdrm
     (wlroots.override { inherit enableXWayland; })
+  ] ++ lib.optionals dbusSupport [
+    dbus
   ];
 
-  mesonFlags = [
-    "-Dsd-bus-provider=libsystemd"
-  ]
+  mesonFlags =
+    [ "-Dsd-bus-provider=${sd-bus-provider}" ]
     ++ lib.optional (!enableXWayland) "-Dxwayland=disabled"
+    ++ lib.optional (!trayEnabled)    "-Dtray=disabled"
   ;
 
   passthru.tests.basic = nixosTests.sway;
diff --git a/pkgs/applications/window-managers/sway/wrapper.nix b/pkgs/applications/window-managers/sway/wrapper.nix
index 827fce897026..c1f531683d70 100644
--- a/pkgs/applications/window-managers/sway/wrapper.nix
+++ b/pkgs/applications/window-managers/sway/wrapper.nix
@@ -8,6 +8,7 @@
 , isNixOS ? false
 
 , enableXWayland ? true
+, dbusSupport ? true
 }:
 
 assert extraSessionCommands != "" -> withBaseWrapper;
@@ -27,7 +28,7 @@ let
        export DBUS_SESSION_BUS_ADDRESS
        exec ${sway}/bin/sway "$@"
      else
-       exec ${dbus}/bin/dbus-run-session ${sway}/bin/sway "$@"
+       exec ${if !dbusSupport then "" else "${dbus}/bin/dbus-run-session"} ${sway}/bin/sway "$@"
      fi
    '';
 in symlinkJoin {