From 35347831a263dba822bc65f8690942c151b91f6d Mon Sep 17 00:00:00 2001 From: Alex David Date: Sat, 7 Jun 2025 13:45:31 -0700 Subject: [PATCH] Refactor GUI combinators This refactors the `gui` combinator to be a composition of pipewire, and the new combinators `wayland` and `pulse`. --- combinators.nix | 66 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/combinators.nix b/combinators.nix index 1c495d1..351e263 100644 --- a/combinators.nix +++ b/combinators.nix @@ -338,18 +338,20 @@ gui = { sig = "Combinator"; doc = '' - Exposes everything required to get gui applications to work normally. + Exposes everything required to get graphical applications to work. + + This composes [pulse](#pulse), [pipewire](#pipewire), + [wayland](#wayland), and forwards/binds a few other paths to get fonts + and cursor to render correctly. ''; impl = combinators: with combinators; compose [ - (readonly (noescape "/etc/fonts")) - (readonly (noescape "\"$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY\"")) - (readwrite (noescape "\"$XDG_RUNTIME_DIR/pulse\"")) - (readonly (noescape "~/.config/dconf")) - (try-fwd-env "DISPLAY") - (fwd-env "WAYLAND_DISPLAY") + pulse + pipewire + wayland (fwd-env "XDG_RUNTIME_DIR") - (fwd-env "XDG_SESSION_TYPE") + (readonly (noescape "/etc/fonts")) + (readonly (noescape "~/.config/dconf")) # Cursor (fwd-env "XCURSOR_THEME") @@ -360,6 +362,52 @@ ; }; + wayland = { + sig = "Combinator"; + doc = '' + Exposes your wayland compositor to the jail. + ''; + impl = combinators: with combinators; + compose [ + (fwd-env "WAYLAND_DISPLAY") + (fwd-env "XDG_RUNTIME_DIR") + (fwd-env "XDG_SESSION_TYPE") + (readonly (noescape "\"$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY\"")) + ] + ; + }; + + unsafe-x11 = { + sig = "Combinator"; + doc = '' + Exposes X11 to the jailed application. + + Note that applications may be able to break out of the jail because X11 + is not designed to be a security boundary. + ''; + impl = combinators: with combinators; + compose [ + (fwd-env "DISPLAY") + (readwrite "/tmp/.X11-unix") + ] + ; + }; + + pulse = { + sig = "Combinator"; + doc = '' + Exposes pulseaudio to the jailed application. + ''; + impl = combinators: with combinators; + compose [ + (fwd-env "XDG_RUNTIME_DIR") + (try-fwd-env "PULSE_SERVER") + (unsafe-add-raw-args "--bind-try /run/pulse /run/pulse") + (unsafe-add-raw-args "--bind-try \"$XDG_RUNTIME_DIR/pulse\" \"$XDG_RUNTIME_DIR/pulse\"") + ] + ; + }; + pipewire = { sig = "Combinator"; doc = '' @@ -367,7 +415,7 @@ ''; impl = combinators: with combinators; compose [ - # TODO - fwd-env XDG_RUNTIME_DIR but first it should update a record in state instead of appending args + (fwd-env "XDG_RUNTIME_DIR") (unsafe-add-raw-args "--bind-try \"$XDG_RUNTIME_DIR/pipewire-0\" \"$XDG_RUNTIME_DIR/pipewire-0\"") (unsafe-add-raw-args "--bind-try /run/pipewire /run/pipewire") ]