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.
This commit is contained in:
Adam Joseph 2022-03-06 12:39:31 +00:00 committed by GitHub
parent a943a5d9da
commit c7a7acb034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -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;

View File

@ -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 {