From c7a7acb034f090a315d79f05475327919a501cfd Mon Sep 17 00:00:00 2001 From: Adam Joseph <54836058+a-m-joseph@users.noreply.github.com> Date: Sun, 6 Mar 2022 12:39:31 +0000 Subject: 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. --- pkgs/applications/window-managers/sway/default.nix | 23 +++++++++++++++++----- pkgs/applications/window-managers/sway/wrapper.nix | 3 ++- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'pkgs/applications/window-managers') 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 { -- cgit 1.4.1