2021-01-25 08:26:54 +00:00
|
|
|
{ lib
|
2023-11-26 16:19:49 +00:00
|
|
|
, sway-unwrapped
|
2019-12-08 12:56:56 +00:00
|
|
|
, makeWrapper, symlinkJoin, writeShellScriptBin
|
|
|
|
, withBaseWrapper ? true, extraSessionCommands ? "", dbus
|
2020-05-08 09:45:27 +00:00
|
|
|
, withGtkWrapper ? false, wrapGAppsHook, gdk-pixbuf, glib, gtk3
|
2019-12-29 06:22:50 +00:00
|
|
|
, extraOptions ? [] # E.g.: [ "--verbose" ]
|
2021-05-11 16:51:43 +00:00
|
|
|
# Used by the NixOS module:
|
|
|
|
, isNixOS ? false
|
2021-10-11 19:41:06 +00:00
|
|
|
|
|
|
|
, enableXWayland ? true
|
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.
2022-03-06 12:39:31 +00:00
|
|
|
, dbusSupport ? true
|
2019-12-08 12:56:56 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert extraSessionCommands != "" -> withBaseWrapper;
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2023-06-10 13:58:45 +00:00
|
|
|
sway = sway-unwrapped.overrideAttrs (oa: { inherit isNixOS enableXWayland; });
|
2023-10-05 10:16:13 +00:00
|
|
|
baseWrapper = writeShellScriptBin sway.meta.mainProgram ''
|
2019-12-08 12:56:56 +00:00
|
|
|
set -o errexit
|
|
|
|
if [ ! "$_SWAY_WRAPPER_ALREADY_EXECUTED" ]; then
|
2023-10-05 10:16:13 +00:00
|
|
|
export XDG_CURRENT_DESKTOP=${sway.meta.mainProgram}
|
2019-12-08 12:56:56 +00:00
|
|
|
${extraSessionCommands}
|
2019-12-31 15:28:52 +00:00
|
|
|
export _SWAY_WRAPPER_ALREADY_EXECUTED=1
|
2019-12-08 12:56:56 +00:00
|
|
|
fi
|
|
|
|
if [ "$DBUS_SESSION_BUS_ADDRESS" ]; then
|
|
|
|
export DBUS_SESSION_BUS_ADDRESS
|
2023-10-05 10:16:13 +00:00
|
|
|
exec ${lib.getExe sway} "$@"
|
2019-12-08 12:56:56 +00:00
|
|
|
else
|
2023-10-05 10:16:13 +00:00
|
|
|
exec ${lib.optionalString dbusSupport "${dbus}/bin/dbus-run-session"} ${lib.getExe sway} "$@"
|
2019-12-08 12:56:56 +00:00
|
|
|
fi
|
|
|
|
'';
|
2023-12-14 20:14:12 +00:00
|
|
|
in symlinkJoin rec {
|
|
|
|
pname = lib.replaceStrings ["-unwrapped"] [""] sway.pname;
|
|
|
|
inherit (sway) version;
|
|
|
|
name = "${pname}-${version}";
|
2019-12-08 12:56:56 +00:00
|
|
|
|
|
|
|
paths = (optional withBaseWrapper baseWrapper)
|
2021-05-11 16:51:43 +00:00
|
|
|
++ [ sway ];
|
2019-12-08 12:56:56 +00:00
|
|
|
|
2022-06-05 14:13:08 +00:00
|
|
|
strictDeps = false;
|
2019-12-08 12:56:56 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ]
|
|
|
|
++ (optional withGtkWrapper wrapGAppsHook);
|
|
|
|
|
2020-05-08 09:45:27 +00:00
|
|
|
buildInputs = optionals withGtkWrapper [ gdk-pixbuf glib gtk3 ];
|
|
|
|
|
|
|
|
# We want to run wrapProgram manually
|
|
|
|
dontWrapGApps = true;
|
2019-12-08 12:56:56 +00:00
|
|
|
|
|
|
|
postBuild = ''
|
2020-05-08 09:45:27 +00:00
|
|
|
${optionalString withGtkWrapper "gappsWrapperArgsHook"}
|
|
|
|
|
2023-10-05 10:16:13 +00:00
|
|
|
wrapProgram $out/bin/${sway.meta.mainProgram} \
|
2019-12-29 06:22:50 +00:00
|
|
|
${optionalString withGtkWrapper ''"''${gappsWrapperArgs[@]}"''} \
|
|
|
|
${optionalString (extraOptions != []) "${concatMapStrings (x: " --add-flags " + x) extraOptions}"}
|
2019-12-08 12:56:56 +00:00
|
|
|
'';
|
|
|
|
|
2021-11-01 14:50:27 +00:00
|
|
|
passthru = {
|
|
|
|
inherit (sway.passthru) tests;
|
2023-10-05 10:16:13 +00:00
|
|
|
providedSessions = [ sway.meta.mainProgram ];
|
2021-11-01 14:50:27 +00:00
|
|
|
};
|
2019-12-08 12:56:56 +00:00
|
|
|
|
2021-05-11 16:51:43 +00:00
|
|
|
inherit (sway) meta;
|
2019-12-08 12:56:56 +00:00
|
|
|
}
|