diff --git a/srcpkgs/xorg-server/template b/srcpkgs/xorg-server/template
index bc1935a4c8d..184dcb473bb 100644
--- a/srcpkgs/xorg-server/template
+++ b/srcpkgs/xorg-server/template
@@ -60,6 +60,14 @@ esac
 
 conf_files="/etc/X11/Xwrapper.config"
 
+pre_configure() {
+	case "$XBPS_TARGET_MACHINE" in
+	*-musl)
+		export CFLAGS+=" -D__uid_t=uid_t -D__gid_t=gid_t"
+		sed -i -e 's/termio.h/termios.h/' hw/xfree86/os-support/xf86_OSlib.h
+		;;
+	esac
+}
 post_install() {
 	vinstall ${FILESDIR}/nvidia-drm-outputclass.conf 644 usr/share/X11/xorg.conf.d
 	vinstall ${FILESDIR}/Xwrapper.config 644 etc/X11