2021-01-25 08:26:54 +00:00
|
|
|
{ lib
|
2020-08-31 17:51:05 +01:00
|
|
|
, sway-unwrapped
|
2019-12-08 12:56:56 +00:00
|
|
|
, makeWrapper, symlinkJoin, writeShellScriptBin
|
|
|
|
, withBaseWrapper ? true, extraSessionCommands ? "", dbus
|
2020-05-08 10:45:27 +01:00
|
|
|
, withGtkWrapper ? false, wrapGAppsHook, gdk-pixbuf, glib, gtk3
|
2019-12-29 06:22:50 +00:00
|
|
|
, extraOptions ? [] # E.g.: [ "--verbose" ]
|
2021-05-11 17:51:43 +01:00
|
|
|
# Used by the NixOS module:
|
|
|
|
, isNixOS ? false
|
2019-12-08 12:56:56 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert extraSessionCommands != "" -> withBaseWrapper;
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2021-05-11 17:51:43 +01:00
|
|
|
sway = sway-unwrapped.override { inherit isNixOS; };
|
2019-12-08 12:56:56 +00:00
|
|
|
baseWrapper = writeShellScriptBin "sway" ''
|
|
|
|
set -o errexit
|
|
|
|
if [ ! "$_SWAY_WRAPPER_ALREADY_EXECUTED" ]; then
|
2021-05-06 14:27:23 +01:00
|
|
|
export XDG_CURRENT_DESKTOP=sway
|
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
|
2021-05-11 17:51:43 +01:00
|
|
|
exec ${sway}/bin/sway "$@"
|
2019-12-08 12:56:56 +00:00
|
|
|
else
|
2021-05-11 17:51:43 +01:00
|
|
|
exec ${dbus}/bin/dbus-run-session ${sway}/bin/sway "$@"
|
2019-12-08 12:56:56 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in symlinkJoin {
|
2021-05-11 17:51:43 +01:00
|
|
|
name = "sway-${sway.version}";
|
2019-12-08 12:56:56 +00:00
|
|
|
|
|
|
|
paths = (optional withBaseWrapper baseWrapper)
|
2021-05-11 17:51:43 +01:00
|
|
|
++ [ sway ];
|
2019-12-08 12:56:56 +00:00
|
|
|
|
|
|
|
nativeBuildInputs = [ makeWrapper ]
|
|
|
|
++ (optional withGtkWrapper wrapGAppsHook);
|
|
|
|
|
2020-05-08 10:45:27 +01: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 10:45:27 +01:00
|
|
|
${optionalString withGtkWrapper "gappsWrapperArgsHook"}
|
|
|
|
|
2019-12-08 12:56:56 +00:00
|
|
|
wrapProgram $out/bin/sway \
|
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
|
|
|
'';
|
|
|
|
|
|
|
|
passthru.providedSessions = [ "sway" ];
|
|
|
|
|
2021-05-11 17:51:43 +01:00
|
|
|
inherit (sway) meta;
|
2019-12-08 12:56:56 +00:00
|
|
|
}
|