feat: add xwayland-satellite

Niri doesn't come with xwayland support, so we provide
xwayland-satellite to have native-like X windows in wayland

Change-Id: I6c1d417e433abda269cfb08b210c55ae688af2b0
diff --git a/packages/xwayland-satellite/default.nix b/packages/xwayland-satellite/default.nix
new file mode 100644
index 0000000..5bfa4fa
--- /dev/null
+++ b/packages/xwayland-satellite/default.nix
@@ -0,0 +1,48 @@
+{ inputs, system, lib, pkg-config, rustPlatform, libclang, xcb-util-cursor, xorg, musl, makeWrapper }: let
+  src = inputs.xwayland-satellite;
+  libraries = [
+    xcb-util-cursor
+    xorg.libxcb
+    musl
+  ];
+  includeArgs = map (library: ''-I"${library.dev}/include"'') libraries;
+  libraryArgs = map (library: ''-L"${library}/lib"'') libraries;
+  extraClangArgs = builtins.concatStringsSep " " (includeArgs ++ libraryArgs);
+  xwayland = inputs.nixpkgs-xwayland-23.legacyPackages.${system}.xwayland; # needed to avoid steam big picture mode failing, see https://github.com/Supreeeme/xwayland-satellite/issues/18
+in rustPlatform.buildRustPackage {
+  pname = "xwayland-satellite";
+  version = "unstable-${src.lastModifiedDate}";
+
+  inherit src;
+
+  cargoLock.lockFile = "${src}/Cargo.lock";
+
+  preBuild = ''
+    export LIBCLANG_PATH="${libclang.lib}/lib"
+    export BINDGEN_EXTRA_CLANG_ARGS='${extraClangArgs}'
+    export LIBRARY_PATH="${lib.makeLibraryPath libraries}"
+  '';
+
+  doCheck = false; # xwayland-satellite fails checks due to not being wrapped at this point...
+
+  nativeBuildInputs = libraries ++ [
+    libclang.lib
+    pkg-config
+    makeWrapper
+  ];
+
+  postInstall = ''
+    wrapProgram $out/bin/xwayland-satellite --suffix PATH : ${lib.makeBinPath [ xwayland ]}
+  '';
+
+  buildInputs = [
+    xwayland
+  ];
+
+  meta = {
+    description = "Allow rootless xwayland integration for wayland compositors";
+    homepage = "https://github.com/Supreeeme/xwayland-satellite";
+    license = lib.licenses.mpl20;
+    maintainers = [ lib.maintainers.minion3665 ];
+  };
+}