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