Merge pull request #75247 from Elyhaka/sway
sway: refactor with a wrapper This moves the wrapper functionality from the NixOS module to a new package (wrapper) that wraps the original sway package (sway-unwrapped). Therefore it's now also possible to properly use Sway on non-NixOS systems out of the box. The new submodule for the wrapperFeatures makes it easy to extend the functionality which should become useful in the future. This also introduces a GTK wrapper feature to fix issues with icon/GTK themes, e.g. when running waybar or wofi. This should also work for #67704. If not, we might have to add some additional dependencies/arguments for this case.
This commit is contained in:
commit
b9b77386b0
@ -4,27 +4,32 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.programs.sway;
|
cfg = config.programs.sway;
|
||||||
swayPackage = pkgs.sway;
|
|
||||||
|
|
||||||
swayWrapped = pkgs.writeShellScriptBin "sway" ''
|
wrapperOptions = types.submodule {
|
||||||
set -o errexit
|
options =
|
||||||
|
let
|
||||||
|
mkWrapperFeature = default: description: mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
inherit default;
|
||||||
|
example = !default;
|
||||||
|
description = "Whether to make use of the ${description}";
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
base = mkWrapperFeature true ''
|
||||||
|
base wrapper to execute extra session commands and prepend a
|
||||||
|
dbus-run-session to the sway command.
|
||||||
|
'';
|
||||||
|
gtk = mkWrapperFeature false ''
|
||||||
|
wrapGAppsHook wrapper to execute sway with required environment
|
||||||
|
variables for GTK applications.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if [ ! "$_SWAY_WRAPPER_ALREADY_EXECUTED" ]; then
|
swayPackage = pkgs.sway.override {
|
||||||
export _SWAY_WRAPPER_ALREADY_EXECUTED=1
|
extraSessionCommands = cfg.extraSessionCommands;
|
||||||
${cfg.extraSessionCommands}
|
withBaseWrapper = cfg.wrapperFeatures.base;
|
||||||
fi
|
withGtkWrapper = cfg.wrapperFeatures.gtk;
|
||||||
|
|
||||||
if [ "$DBUS_SESSION_BUS_ADDRESS" ]; then
|
|
||||||
export DBUS_SESSION_BUS_ADDRESS
|
|
||||||
exec ${swayPackage}/bin/sway "$@"
|
|
||||||
else
|
|
||||||
exec ${pkgs.dbus}/bin/dbus-run-session ${swayPackage}/bin/sway "$@"
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
swayJoined = pkgs.symlinkJoin {
|
|
||||||
name = "sway-joined";
|
|
||||||
paths = [ swayWrapped swayPackage ];
|
|
||||||
passthru.providedSessions = [ "sway" ];
|
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
options.programs.sway = {
|
options.programs.sway = {
|
||||||
@ -36,6 +41,15 @@ in {
|
|||||||
Please have a look at the "extraSessionCommands" example for running
|
Please have a look at the "extraSessionCommands" example for running
|
||||||
programs natively under Wayland'';
|
programs natively under Wayland'';
|
||||||
|
|
||||||
|
wrapperFeatures = mkOption {
|
||||||
|
type = wrapperOptions;
|
||||||
|
default = { };
|
||||||
|
example = { gtk = true; };
|
||||||
|
description = ''
|
||||||
|
Attribute set of features to enable in the wrapper.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
extraSessionCommands = mkOption {
|
extraSessionCommands = mkOption {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
@ -56,7 +70,7 @@ in {
|
|||||||
extraPackages = mkOption {
|
extraPackages = mkOption {
|
||||||
type = with types; listOf package;
|
type = with types; listOf package;
|
||||||
default = with pkgs; [
|
default = with pkgs; [
|
||||||
swaylock swayidle swaybg
|
swaylock swayidle
|
||||||
xwayland rxvt_unicode dmenu
|
xwayland rxvt_unicode dmenu
|
||||||
];
|
];
|
||||||
defaultText = literalExample ''
|
defaultText = literalExample ''
|
||||||
@ -76,8 +90,17 @@ in {
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = cfg.extraSessionCommands != "" -> cfg.wrapperFeatures.base;
|
||||||
|
message = ''
|
||||||
|
The extraSessionCommands for Sway will not be run if
|
||||||
|
wrapperFeatures.base is disabled.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
environment = {
|
environment = {
|
||||||
systemPackages = [ swayJoined ] ++ cfg.extraPackages;
|
systemPackages = [ swayPackage ] ++ cfg.extraPackages;
|
||||||
etc = {
|
etc = {
|
||||||
"sway/config".source = mkOptionDefault "${swayPackage}/etc/sway/config";
|
"sway/config".source = mkOptionDefault "${swayPackage}/etc/sway/config";
|
||||||
#"sway/security.d".source = mkOptionDefault "${swayPackage}/etc/sway/security.d/";
|
#"sway/security.d".source = mkOptionDefault "${swayPackage}/etc/sway/security.d/";
|
||||||
@ -89,7 +112,7 @@ in {
|
|||||||
fonts.enableDefaultFonts = mkDefault true;
|
fonts.enableDefaultFonts = mkDefault true;
|
||||||
programs.dconf.enable = mkDefault true;
|
programs.dconf.enable = mkDefault true;
|
||||||
# To make a Sway session available if a display manager like SDDM is enabled:
|
# To make a Sway session available if a display manager like SDDM is enabled:
|
||||||
services.xserver.displayManager.sessionPackages = [ swayJoined ];
|
services.xserver.displayManager.sessionPackages = [ swayPackage ];
|
||||||
};
|
};
|
||||||
|
|
||||||
meta.maintainers = with lib.maintainers; [ gnidorah primeos colemickens ];
|
meta.maintainers = with lib.maintainers; [ gnidorah primeos colemickens ];
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
, pkgconfig, scdoc
|
, pkgconfig, scdoc
|
||||||
, wayland, libxkbcommon, pcre, json_c, dbus, libevdev
|
, wayland, libxkbcommon, pcre, json_c, dbus, libevdev
|
||||||
, pango, cairo, libinput, libcap, pam, gdk-pixbuf
|
, pango, cairo, libinput, libcap, pam, gdk-pixbuf
|
||||||
, wlroots, wayland-protocols, swaybg
|
, wlroots, wayland-protocols
|
||||||
}:
|
}:
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
pname = "sway";
|
pname = "sway-unwrapped";
|
||||||
version = "1.2";
|
version = "1.2";
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
@ -22,7 +22,9 @@ stdenv.mkDerivation rec {
|
|||||||
./load-configuration-from-etc.patch
|
./load-configuration-from-etc.patch
|
||||||
];
|
];
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgconfig meson ninja scdoc makeWrapper ];
|
nativeBuildInputs = [
|
||||||
|
pkgconfig meson ninja scdoc
|
||||||
|
];
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
wayland libxkbcommon pcre json_c dbus libevdev
|
wayland libxkbcommon pcre json_c dbus libevdev
|
||||||
@ -37,10 +39,6 @@ stdenv.mkDerivation rec {
|
|||||||
"-Dtray=enabled" "-Dman-pages=enabled"
|
"-Dtray=enabled" "-Dman-pages=enabled"
|
||||||
];
|
];
|
||||||
|
|
||||||
postInstall = ''
|
|
||||||
wrapProgram $out/bin/sway --prefix PATH : "${swaybg}/bin"
|
|
||||||
'';
|
|
||||||
|
|
||||||
meta = with stdenv.lib; {
|
meta = with stdenv.lib; {
|
||||||
description = "i3-compatible tiling Wayland compositor";
|
description = "i3-compatible tiling Wayland compositor";
|
||||||
homepage = https://swaywm.org;
|
homepage = https://swaywm.org;
|
||||||
|
50
pkgs/applications/window-managers/sway/wrapper.nix
Normal file
50
pkgs/applications/window-managers/sway/wrapper.nix
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{ lib, stdenv
|
||||||
|
, sway-unwrapped, swaybg
|
||||||
|
, makeWrapper, symlinkJoin, writeShellScriptBin
|
||||||
|
, withBaseWrapper ? true, extraSessionCommands ? "", dbus
|
||||||
|
, withGtkWrapper ? false, wrapGAppsHook, gdk-pixbuf
|
||||||
|
}:
|
||||||
|
|
||||||
|
assert extraSessionCommands != "" -> withBaseWrapper;
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
baseWrapper = writeShellScriptBin "sway" ''
|
||||||
|
set -o errexit
|
||||||
|
if [ ! "$_SWAY_WRAPPER_ALREADY_EXECUTED" ]; then
|
||||||
|
export _SWAY_WRAPPER_ALREADY_EXECUTED=1
|
||||||
|
${extraSessionCommands}
|
||||||
|
fi
|
||||||
|
if [ "$DBUS_SESSION_BUS_ADDRESS" ]; then
|
||||||
|
export DBUS_SESSION_BUS_ADDRESS
|
||||||
|
exec ${sway-unwrapped}/bin/sway "$@"
|
||||||
|
else
|
||||||
|
exec ${dbus}/bin/dbus-run-session ${sway-unwrapped}/bin/sway "$@"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
in symlinkJoin {
|
||||||
|
name = "sway-${sway-unwrapped.version}";
|
||||||
|
|
||||||
|
paths = (optional withBaseWrapper baseWrapper)
|
||||||
|
++ [ sway-unwrapped ];
|
||||||
|
|
||||||
|
nativeBuildInputs = [ makeWrapper ]
|
||||||
|
++ (optional withGtkWrapper wrapGAppsHook);
|
||||||
|
|
||||||
|
buildInputs = optional withGtkWrapper gdk-pixbuf;
|
||||||
|
|
||||||
|
postBuild = ''
|
||||||
|
# We want to run wrapProgram manually to only wrap sway and add swaybg:
|
||||||
|
export dontWrapGApps=true
|
||||||
|
${optionalString withGtkWrapper "wrapGAppsHook"}
|
||||||
|
wrapProgram $out/bin/sway \
|
||||||
|
--prefix PATH : "${swaybg}/bin" ${optionalString withGtkWrapper ''\
|
||||||
|
"''${gappsWrapperArgs[@]}"
|
||||||
|
''}
|
||||||
|
'';
|
||||||
|
|
||||||
|
passthru.providedSessions = [ "sway" ];
|
||||||
|
|
||||||
|
inherit (sway-unwrapped) meta;
|
||||||
|
}
|
@ -19391,7 +19391,8 @@ in
|
|||||||
|
|
||||||
wlroots = callPackage ../development/libraries/wlroots { };
|
wlroots = callPackage ../development/libraries/wlroots { };
|
||||||
|
|
||||||
sway = callPackage ../applications/window-managers/sway { };
|
sway-unwrapped = callPackage ../applications/window-managers/sway { };
|
||||||
|
sway = callPackage ../applications/window-managers/sway/wrapper.nix { };
|
||||||
swaybg = callPackage ../applications/window-managers/sway/bg.nix { };
|
swaybg = callPackage ../applications/window-managers/sway/bg.nix { };
|
||||||
swayidle = callPackage ../applications/window-managers/sway/idle.nix { };
|
swayidle = callPackage ../applications/window-managers/sway/idle.nix { };
|
||||||
swaylock = callPackage ../applications/window-managers/sway/lock.nix { };
|
swaylock = callPackage ../applications/window-managers/sway/lock.nix { };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user