Using X-Plane12 on Linux with Flatpak

#blog #xplane

Using X-Plane on Linux generally is supported. However, it comes with a few shortcomings around Plugins, Planes and sandboxing which are not present on systems like Windows. This post shows some changes and tricks I needed to do to make this a pleasant experience. It also is meant to show that Flightsim with X-Plane 12 on Linux is realistically possible and usable and not just a thing for the extreme people (though there is some work you need to do).

Setting up Steam

On paper it is as simple as installing it from Flathub. However, this will not work with any Java based plugins, and it will not work with some things like LittleNavmap.
Therefore, we need to build it ourselves and change some parts of the Flatpak to have the missing dependencies installed.

Getting the Steam Flatpak sources and Flatpak dependencies

Flatpak has all the whole Steam app publicly on GitHub. This means we can easily build it ourselves.

First we need to get some dependencies for that:

After having these dependencies installed, we can go ahead and clone the repository using git clone https://github.com/flathub/com.valvesoftware.Steam.git. After doing this change into the created folder for the next steps.

Adding Dependencies to the Steam Flatpak

With the dependencies out of the way, we next need to start changing some things. For this, we need to do a few changes to the com.valvesoftware.Steam.yml as well as a single change to the steam_wrapper/steam_wrapper.py.

First, we modify the com.valvesoftware.Steam.yml. For this, we use this patch file:

diff --git a/com.valvesoftware.Steam.yml b/com.valvesoftware.Steam.yml
index 71ba438..36a7210 100644
--- a/com.valvesoftware.Steam.yml
+++ b/com.valvesoftware.Steam.yml
@@ -1,9 +1,9 @@
 app-id: com.valvesoftware.Steam
-runtime: org.freedesktop.Platform
-runtime-version: &runtime-version '22.08'
+runtime: org.gnome.Platform
+runtime-version: &runtime-version '44'
 x-gl-version: &gl-version '1.4'
 x-gl-versions: &gl-versions 22.08;22.08-extra;1.4
-sdk: org.freedesktop.Sdk
+sdk: org.gnome.Sdk
 command: steam-wrapper
 separate-locales: false
 rename-icon: steam
@@ -12,9 +12,9 @@ tags:
   - proprietary
 
 sdk-extensions:
-  - org.freedesktop.Sdk.Compat.i386
   - org.freedesktop.Sdk.Extension.toolchain-i386
-
+  - org.gnome.Sdk.Compat.i386
+  - org.freedesktop.Sdk.Extension.openjdk17
 finish-args:
   - --share=ipc
   - --socket=wayland
@@ -62,7 +62,7 @@ finish-args:
   - --env=DBUS_FATAL_WARNINGS=0
   - --env=SSL_CERT_DIR=/etc/ssl/certs
   - --env=STEAM_EXTRA_COMPAT_TOOLS_PATHS=/app/share/steam/compatibilitytools.d:/app/utils/share/steam/compatibilitytools.d
-  - --env=PATH=/app/bin:/app/utils/bin:/usr/bin
+  - --env=PATH=/app/jre/bin:/app/bin:/app/utils/bin:/usr/bin
   - --env=PYTHONPATH=/app/utils/lib/python3.10/site-packages
   - --env=PROTON_DEBUG_DIR=/var/tmp
   - --env=XDG_CONFIG_DIRS=/etc/xdg:/usr/lib/x86_64-linux-gnu/GL:/usr/lib/i386-linux-gnu/GL
@@ -71,13 +71,13 @@ finish-args:
   - --require-version=1.0.0
 
 add-extensions:
-  org.freedesktop.Platform.Compat.i386:
+  org.gnome.Platform.Compat.i386:
     directory: lib/i386-linux-gnu
-    version: *runtime-version
+    version: '43'
 
-  org.freedesktop.Platform.Compat.i386.Debug:
+  org.gnome.Platform.Compat.i386.Debug:
     directory: lib/debug/lib/i386-linux-gnu
-    version: *runtime-version
+    version: '43'
     no-autodownload: true
 
   org.freedesktop.Platform.GL32:
@@ -147,6 +147,20 @@ cleanup-commands:
   - python3 -m compileall --invalidation-mode=unchecked-hash /app
 
 modules:
+  - name: zenity
+    buildsystem: meson
+    sources:
+      - type: archive
+        url: https://download.gnome.org/sources/zenity/3.41/zenity-3.41.0.tar.xz
+        sha256: 19b676c3510e22badfcc3204062d432ba537402f5e0ae26128c0d90c954037e1
+  - name: openjdk
+    buildsystem: simple
+    build-commands:
+      - /usr/lib/sdk/openjdk17/install.sh
+
+  - shared-modules/gtk2/gtk2.json
+
+  - shared-modules/glu/glu-9.json
 
   - modules.yml
 
@@ -232,3 +246,12 @@ modules:
     sources:
       - type: dir
         path: resources
+  - name: double-conversion
+    buildsystem: cmake-ninja
+    config-opts:
+      - "-DBUILD_SHARED_LIBS=ON"
+    sources:
+      - type: archive
+        url: "https://github.com/google/double-conversion/archive/v3.1.5.tar.gz"
+        sha256: a63ecb93182134ba4293fd5f22d6e08ca417caafa244afaa751cbfddf6415b13
+        dest-filename: double-conversion-3.1.5.tar.gz

To apply the diff, save it in a file like com.valvesoftware.Steam.yml.diff and use patch -i com.valvesoftware.Steam.yml.diff to apply the changes.

This will change the SDK used to gnome because it contains QT dependencies needed for littlenavconnect and also installs java17 and further dependencies I found to be needed.

The next step is to patch the steam_wrapper/steam_wrapper.py:

diff --git a/steam_wrapper/steam_wrapper.py b/steam_wrapper/steam_wrapper.py
index c9b52fc..aefa735 100644
--- a/steam_wrapper/steam_wrapper.py
+++ b/steam_wrapper/steam_wrapper.py
@@ -405,7 +405,7 @@ def check_extensions(flatpak_info):
     installed_ext_ids = set(flatpak_info["runtime-extensions"]) | \
                         set(flatpak_info["app-extensions"])
 
-    compat_ids = ["org.freedesktop.Platform.Compat.i386"]
+    compat_ids = ["org.gnome.Platform.Compat.i386"]
     # For each installed .GL. extension, check for its .GL32. counterpart
     GL_EXT_PREFIX = "org.freedesktop.Platform.GL"
     for ext_id in installed_ext_ids:

Make sure to save the diff in the root folder of the repository and apply it as before. This patch ensures that the app still starts with the gnome platform.

Last but not least, you need to run ./build.sh and wait for it to complete. With this, you should have all the necessary dependencies for planes like the Airfoillabs C172 and for Plugins like Littlenavmap.

Installing X-Plane 12 can happen as with any Game but make sure to use the native Linux version and not the Proton Version.

Plugins, their issues and how to workaround them

Linux has no perfect support by Plugin Devs. Many of them do provide Linux plugins, but often they are not tested or don't explain the dependencies required. Sometimes you even encounter issues due to the way things had been linked. A notable example of a missing Plugin is Navigraph which even in 2023 don't see a need to provide their plugin to Linux users or let them build their own without violating their licence.

Additionally, the Flatpak does sandbox memory. Meaning, plugins interacting with other Apps cannot share memory. I encountered this with both XPilot and Little Navmap, and the required workarounds are outlined below.

XPilot

XPilot is fairly straightforward but due to some bugs with the installer and due to the usage of shared memory needs extra steps.

Firstly, if you try the installer and end up with no buttons to click and no way of resizing the window, the trick is to use text mode. You can activate it by using the terminal and appending --mode text. After that, follow the installer as you would with the UI.

After you have installed XPilot you next need to activate its shared PC mode. This is necessary since otherwise the Client App will not be able to reach the X-Plane Plugin. For this, you follow the guide at https://xpilot-project.org/docs/#/client?id=running-xpilot-over-a-network and instead of using .visualip make sure to use .simip. Additionally, use the ip of your local network instead of localhost.

Little Navmap

Little Navmap is a little more work as we need to run an external Application (Little Navconnect) within the steam flatpak.

The easiest way to do this is to copy the Little Navconnect application next to the Plugin in your Xplane plugin folder.

After doing that, you need to open a shell within the flatpak. This can be done by using flatpak run --command=/bin/bash com.valvesoftware.Steam (Do NOT use flatpak enter as this unsets necessary Environment variables.). Inside the new shell, navigate to your X-Plane install folder and the Little Navconnect application. You can run it by typing ./littlenavconnect and keeping the window open.

Next, you also need to make sure that LittleNavMap knows where x-plane is at. If it doesn't exist yet, create a x-plane_install_12.txt file at $HOME/.x-plane containing the absolute path to your X-Plane 12 installation (make sure to do this from a normal terminal outside your flatpak).

After doing these steps you can start and use LittleNavMap as normal but need to make sure to use the Network Mode to connect to your simulator.

Afterword

All in all it is fairly straightforward and enjoyable to use on Linux. Not having Navigraph however is a pain. Luckily, Little Navmap has most if not all required features as well and works as a good replacement.
If you have any questions about this, feel free to write a Comment below :)

Appendix

Sources