Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
Seanaye/fix/appimage xkb (#8011)
Sean Aye955caf586b5b
diff --git a/nix-support/appimage-glib-networking.nix b/nix-support/appimage-glib-networking.nixnew file mode 100644index 0000000000..40c82e79b6--- /dev/null+++ b/nix-support/appimage-glib-networking.nix@@ -0,0 +1,20 @@+{+ lib,+ glib-networking,+ libproxy,+}:+(glib-networking.override { inherit libproxy; }).overrideAttrs (+ old:+ let+ nixSchemaPatch = patch: lib.hasSuffix "hardcode-gsettings.patch" (toString patch);+ removed = lib.filter nixSchemaPatch old.patches;+ in+ {+ pname = "glib-networking-appimage";+ # The GNOME resolver must use the AppImage's GSETTINGS_SCHEMA_DIR, not+ # nixpkgs' explicit schema source in /nix/store. Keep all other patches.+ patches =+ assert lib.assertMsg (builtins.length removed == 1) "Review glib-networking's Nix schema patch";+ (lib.filter (patch: !(nixSchemaPatch patch)) old.patches) ++ [ ./appimage-ssl-cert-file.patch ];+ }+)diff --git a/nix-support/appimage-libproxy.nix b/nix-support/appimage-libproxy.nixnew file mode 100644index 0000000000..60a5e187aa--- /dev/null+++ b/nix-support/appimage-libproxy.nix@@ -0,0 +1,27 @@+{+ lib,+ libproxy,+ glib,+ gsettings-desktop-schemas,+}:+libproxy.overrideAttrs (+ old:+ let+ nixSchemaPatch =+ patch:+ lib.hasSuffix "hardcode-gsettings.patch" (toString patch)+ || lib.hasSuffix "skip-gsettings-detection.patch" (toString patch);+ removed = lib.filter nixSchemaPatch old.patches;+ in+ {+ pname = "libproxy-appimage";+ # Restore upstream's GSettings lookup so the bundled backend honors the+ # launcher's GSETTINGS_SCHEMA_DIR instead of opening a Nix store directory.+ patches =+ assert lib.assertMsg (builtins.length removed == 2) "Review libproxy's Nix schema patches";+ lib.filter (patch: !(nixSchemaPatch patch)) old.patches;+ preCheck = (old.preCheck or "") + ''+ export GSETTINGS_SCHEMA_DIR="${glib.getSchemaPath gsettings-desktop-schemas}"+ '';+ }+)diff --git a/nix-support/appimage-ssl-cert-file.patch b/nix-support/appimage-ssl-cert-file.patchnew file mode 100644index 0000000000..8cf2aaa288--- /dev/null+++ b/nix-support/appimage-ssl-cert-file.patch@@ -0,0 +1,20 @@+diff --git a/tls/gnutls/gtlsbackend-gnutls.c b/tls/gnutls/gtlsbackend-gnutls.c+--- a/tls/gnutls/gtlsbackend-gnutls.c++++ b/tls/gnutls/gtlsbackend-gnutls.c+@@ -135,7 +135,15 @@ g_tls_backend_gnutls_get_default_database (GTlsBackend *backend)+ }+ else+ {+- result = G_TLS_DATABASE (g_tls_database_gnutls_new (&error));++ const char *ca_file = g_getenv ("SSL_CERT_FILE");++ /* The AppImage launcher discovers the host's CA bundle. An explicit++ * invalid bundle must fail closed, not fall back to other trust roots.++ */++ if (ca_file && *ca_file)++ result = g_initable_new (G_TYPE_TLS_FILE_DATABASE_GNUTLS,++ NULL, &error, "anchors", ca_file, NULL);++ else++ result = G_TLS_DATABASE (g_tls_database_gnutls_new (&error));+ if (error)+ {+ g_warning ("Failed to load TLS database: %s", error->message);diff --git a/nix-support/appimage-xdg-utils.nix b/nix-support/appimage-xdg-utils.nixnew file mode 100644index 0000000000..0bf70ba3e1--- /dev/null+++ b/nix-support/appimage-xdg-utils.nix@@ -0,0 +1,16 @@+{ runCommand, xdg-utils }:+let+ # Preserve upstream PATH-based commands; resholve embeds Nix tool/data paths.+ portable = xdg-utils.overrideAttrs {+ preFixup = "";+ dontPatchShebangs = true;+ };+in+runCommand "tauri-appimage-xdg-utils" { dontPatchShebangs = true; } ''+ mkdir -p "$out/bin" "$out/libexec/macro"+ for helper in xdg-open xdg-mime; do+ install -m0755 ${../nix/appimage/xdg-helper.sh} "$out/bin/$helper"+ install -m0755 "${portable}/bin/$helper" "$out/libexec/macro/$helper"+ done+ install -m0644 ${../nix/appimage/host-environment.sh} "$out/libexec/macro/host-environment.sh"+''diff --git a/nix/appimage/host-environment.sh b/nix/appimage/host-environment.shnew file mode 100755index 0000000000..39366bbefa--- /dev/null+++ b/nix/appimage/host-environment.sh@@ -0,0 +1,38 @@+#!/usr/bin/env bash+# Variables modified by our hooks or the native AppRun, not general user settings.+macro_host_variables=(+ PATH LD_LIBRARY_PATH XDG_DATA_DIRS PERLLIB QT_PLUGIN_PATH PYTHONDONTWRITEBYTECODE+ GIO_EXTRA_MODULES GSETTINGS_SCHEMA_DIR XKB_CONFIG_ROOT SSL_CERT_FILE+ WEBKIT_INJECTED_BUNDLE_PATH GST_REGISTRY_REUSE_PLUGIN_SCANNER+ GST_PLUGIN_SYSTEM_PATH_1_0 GST_PLUGIN_PATH_1_0 GST_PLUGIN_SCANNER_1_0 GST_PTP_HELPER_1_0+)++macro_capture_host_environment() {+ [[ ${MACRO_APPIMAGE_HOST_ENV_CAPTURED:-} == 1 ]] && return 0+ local variable saved+ for variable in "${macro_host_variables[@]}"; do+ saved="MACRO_APPIMAGE_ORIGINAL_$variable"+ unset "$saved"+ if [[ -v $variable ]]; then+ printf -v "$saved" '%s' "${!variable}"+ export "${saved?}"+ fi+ done+ export MACRO_APPIMAGE_HOST_ENV_CAPTURED=1+}++macro_restore_host_environment() {+ [[ ${MACRO_APPIMAGE_HOST_ENV_CAPTURED:-} == 1 ]] || return 0+ local variable saved+ for variable in "${macro_host_variables[@]}"; do+ saved="MACRO_APPIMAGE_ORIGINAL_$variable"+ if [[ -v $saved ]]; then+ printf -v "$variable" '%s' "${!saved}"+ export "${variable?}"+ else+ unset "$variable"+ fi+ unset "$saved"+ done+ unset MACRO_APPIMAGE_HOST_ENV_CAPTURED APPDIR APPIMAGE APPIMAGE_SILENT_INSTALL APPIMAGE_DEBUG_EXEC _APPIMAGE_SCHEMA_DIR+}diff --git a/nix/appimage/patch_apprun.py b/nix/appimage/patch_apprun.pynew file mode 100755index 0000000000..a8ba4df28c--- /dev/null+++ b/nix/appimage/patch_apprun.py@@ -0,0 +1,31 @@+#!/usr/bin/env python3+"""Let the runtime hook own GSETTINGS_SCHEMA_DIR, without replacing AppRun."""++import sys+from pathlib import Path++SCHEMA_VARIABLE = b"GSETTINGS_SCHEMA_DIR"+IGNORED_VARIABLE = b"_APPIMAGE_SCHEMA_DIR"+++def patch_apprun(source, destination):+ data = source.read_bytes()+ # The pinned legacy launcher always appends ':' to this variable, even+ # when unset. GLib requires one directory, not a colon-separated list.+ # Rename both the getenv key and the assignment-format key, preserving ELF+ # offsets and all other behavior (including the cwd used by WebKit helpers).+ if len(SCHEMA_VARIABLE) != len(IGNORED_VARIABLE):+ raise ValueError("AppRun replacement must preserve ELF offsets")+ if (+ not data.startswith(b"\x7fELF")+ or data.count(SCHEMA_VARIABLE) != 2+ or data.count(SCHEMA_VARIABLE + b"\0") != 1+ or data.count(SCHEMA_VARIABLE + b"=") != 1+ ):+ raise ValueError("Unsupported AppRun: expected one schema getter and setter")+ destination.write_bytes(data.replace(SCHEMA_VARIABLE, IGNORED_VARIABLE))+ destination.chmod(0o755)+++if __name__ == "__main__":+ patch_apprun(Path(sys.argv[1]), Path(sys.argv[2]))diff --git a/nix/appimage/relocate.py b/nix/appimage/relocate.pyindex 47aa3c886b..7b4dc0551d 100755--- a/nix/appimage/relocate.py+++ b/nix/appimage/relocate.py@@ -22,6 +22,20 @@ def elf_files(root):yield path+def check_schema_paths(appdir):+ for relative in (+ "usr/lib/libpxbackend-1.0.so",+ "usr/lib/libgiognomeproxy.so",+ "usr/lib/gio/modules/libgiognomeproxy.so",+ ):+ path = Path(appdir) / relative+ if path.is_file() and re.search(+ rb"/nix/store/[^\x00\n]*gsettings-desktop-schemas[^\x00\n]*/glib-2\.0/schemas",+ path.read_bytes(),+ ):+ raise RuntimeError(f"Nix-only GSettings lookup in {path}")++def relocate(appdir):appdir = Path(appdir).resolve()libdir = appdir / "usr/lib"@@ -116,6 +130,7 @@ def relocate(appdir):for field in ("needed", "rpath"):if "/nix/store/" in patchelf(path, f"--print-{field}"):raise RuntimeError(f"unrelocated {field}: {path}")+ check_schema_paths(appdir)print(f"Relocated {len(dynamic)} ELF files in {appdir}")diff --git a/nix/appimage/runtime-hook.sh b/nix/appimage/runtime-hook.shnew file mode 100755index 0000000000..06a3810979--- /dev/null+++ b/nix/appimage/runtime-hook.sh@@ -0,0 +1,42 @@+#!/usr/bin/env bash+# Sourced by linuxdeploy's AppRun before it launches the application.+export APPDIR="${APPDIR:-"$(dirname "$(realpath "$0")")"}"+# This hook sorts before other hooks, so external helpers can restore the+# caller's environment rather than exporting AppImage libraries to host apps.+# shellcheck disable=SC1091+source "$APPDIR/usr/libexec/macro/host-environment.sh"+macro_capture_host_environment+export WEBKIT_INJECTED_BUNDLE_PATH="$APPDIR/usr/lib"+# Nix's libxkbcommon embeds a store path that does not exist on other distros.+export XKB_CONFIG_ROOT="$APPDIR/usr/share/X11/xkb"+# The patched AppRun leaves this single-directory value intact (no ':' suffix).+export GSETTINGS_SCHEMA_DIR="$APPDIR/usr/share/glib-2.0/schemas"+# Use the host's managed TLS trust, not a build-time Nix path. Preserve explicit+# overrides (including invalid ones): the TLS backend must fail closed on those.+macro_find_ca_bundle() {+ local root="${1:-}" candidate+ for candidate in \+ etc/ssl/certs/ca-certificates.crt \+ etc/pki/tls/certs/ca-bundle.crt \+ etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem \+ etc/ssl/ca-bundle.pem \+ etc/ssl/cert.pem; do+ if [ -r "$root/$candidate" ] && [ -s "$root/$candidate" ]; then+ printf '%s\n' "$root/$candidate"+ return 0+ fi+ done+ return 1+}+if [ -z "${SSL_CERT_FILE:-}" ]; then+ if ca_file=$(macro_find_ca_bundle); then+ export SSL_CERT_FILE="$ca_file"+ fi+fi+gio_modules="$APPDIR/usr/lib/gio/modules"+if [ -d "$gio_modules" ]; then+ case ":${GIO_EXTRA_MODULES:-}:" in+ *:"$gio_modules":*) ;;+ *) export GIO_EXTRA_MODULES="$gio_modules${GIO_EXTRA_MODULES:+:$GIO_EXTRA_MODULES}" ;;+ esac+fidiff --git a/nix/appimage/test_apprun.py b/nix/appimage/test_apprun.pynew file mode 100644index 0000000000..10749bd902--- /dev/null+++ b/nix/appimage/test_apprun.py@@ -0,0 +1,55 @@+"""Guard the narrow patch to the pinned native AppRun's environment table."""++import tempfile+import unittest+from pathlib import Path++from patch_apprun import IGNORED_VARIABLE, SCHEMA_VARIABLE, patch_apprun+++class AppRunPatchTest(unittest.TestCase):+ def setUp(self):+ self.temp = tempfile.TemporaryDirectory()+ self.addCleanup(self.temp.cleanup)+ self.source = Path(self.temp.name) / "original"+ self.output = Path(self.temp.name) / "patched"++ def test_preserves_size_source_and_surrounding_bytes(self):+ data = (+ b"\x7fELFprefix\0"+ + SCHEMA_VARIABLE+ + b"\0middle\0"+ + SCHEMA_VARIABLE+ + b"=%s/schemas/:%s\0suffix\0"+ )+ self.source.write_bytes(data)+ patch_apprun(self.source, self.output)+ self.assertEqual(self.source.read_bytes(), data)+ self.assertEqual(len(self.output.read_bytes()), len(data))+ self.assertEqual(+ self.output.read_bytes(),+ b"\x7fELFprefix\0"+ + IGNORED_VARIABLE+ + b"\0middle\0"+ + IGNORED_VARIABLE+ + b"=%s/schemas/:%s\0suffix\0",+ )+ self.assertEqual(self.output.stat().st_mode & 0o777, 0o755)++ def test_rejects_missing_or_ambiguous_entries(self):+ for getters, setters in ((0, 1), (1, 0), (2, 1), (1, 2)):+ with self.subTest(getters=getters, setters=setters):+ self.source.write_bytes(+ b"\x7fELF"+ + (SCHEMA_VARIABLE + b"\0") * getters+ + (SCHEMA_VARIABLE + b"=%s\0") * setters+ )+ with self.assertRaisesRegex(ValueError, "Unsupported AppRun"):+ patch_apprun(self.source, self.output)+ self.assertFalse(self.output.exists())++ def test_rejects_non_elf_input(self):+ self.source.write_bytes(SCHEMA_VARIABLE)+ with self.assertRaisesRegex(ValueError, "Unsupported AppRun"):+ patch_apprun(self.source, self.output)+ self.assertFalse(self.output.exists())diff --git a/nix/appimage/test_packaging.py b/nix/appimage/test_packaging.pyindex d4f0b38e4e..5453c68afe 100644--- a/nix/appimage/test_packaging.py+++ b/nix/appimage/test_packaging.py@@ -173,6 +173,21 @@ class PackagingTest(unittest.TestCase):relocate(self.appdir)self.assertEqual(bundled.read_bytes(), before)+ def test_relocation_rejects_nix_only_proxy_schema_paths(self):+ self.populate()+ for name in ("libpxbackend-1.0.so", "libgiognomeproxy.so"):+ with self.subTest(library=name):+ source = self.compile(+ name,+ 'const char schema_dir[] = "/nix/store/fixture-gsettings-desktop-schemas/share/glib-2.0/schemas";',+ [],+ )+ bundled = self.bundle_lib / name+ shutil.copy2(source, bundled)+ with self.assertRaisesRegex(RuntimeError, "Nix-only GSettings"):+ relocate(self.appdir)+ bundled.unlink()+def test_relocation_rejects_conflicting_sonames(self):self.populate()conflicting = self.bundle_lib / "conflicting.so"diff --git a/nix/appimage/test_runtime.sh b/nix/appimage/test_runtime.shnew file mode 100755index 0000000000..7fc5ea3ed6--- /dev/null+++ b/nix/appimage/test_runtime.sh@@ -0,0 +1,92 @@+#!/usr/bin/env bash+set -euo pipefail+source_dir=$(cd "$(dirname "$0")" && pwd)+hook="$source_dir/runtime-hook.sh"+data=${1:?usage: test_runtime.sh <xkb-data> <schemas> <gio-modules> <AppRun> <libproxy> <ca-bundle>}+schemas=${2:?missing bundled schemas}+modules=${3:?missing GIO modules}+apprun=${4:?missing real AppRun executable}+libproxy=${5:?missing portable libproxy}+ca_bundle=${6:?missing test CA bundle}+xkb_smoke="$PWD/xkb-smoke"+settings_smoke="$PWD/settings-smoke"+tls_smoke="$PWD/tls-smoke"++# shellcheck disable=SC2046+cc -Wall -Wextra -Werror "$source_dir/test_xkb.c" $(pkg-config --cflags --libs xkbcommon) -o "$xkb_smoke"+# shellcheck disable=SC2046+cc -Wall -Wextra -Werror "$source_dir/test_settings.c" $(pkg-config --cflags --libs gio-2.0) -ldl -o "$settings_smoke"+# shellcheck disable=SC2046+cc -Wall -Wextra -Werror "$source_dir/test_tls.c" $(pkg-config --cflags --libs gio-2.0) -o "$tls_smoke"++# Prove that neither fixture silently falls back to the build host's data.+if env XKB_CONFIG_ROOT="$PWD/missing-xkb-data" "$xkb_smoke"; then+ echo "XKB smoke test unexpectedly used host keyboard data" >&2+ exit 1+fi+if env GSETTINGS_SCHEMA_DIR="$PWD/missing-schemas" "$settings_smoke"; then+ echo "GSettings smoke test unexpectedly used host schemas" >&2+ exit 1+fi++appdir="$PWD/Macro.AppDir"+mkdir -p "$appdir/usr/share/X11" "$appdir/usr/share/glib-2.0" "$appdir/usr/lib/gio" "$appdir/usr/bin" "$appdir/usr/libexec/macro"+cp "$source_dir/host-environment.sh" "$appdir/usr/libexec/macro/host-environment.sh"+cp -r "$data" "$appdir/usr/share/X11/xkb"+cp -r "$schemas" "$appdir/usr/share/glib-2.0/schemas"+cp -rL "$modules" "$appdir/usr/lib/gio/modules"+install -m0755 "$libproxy/lib/libproxy.so.1" "$appdir/usr/lib/libproxy.so.1"+install -m0755 "$libproxy/lib/libproxy/libpxbackend-1.0.so" "$appdir/usr/lib/libpxbackend-1.0.so"+# Nix's schema directory exists in this sandbox: reject baked-in lookups before+# running the fixtures so the host cannot mask a broken proxy module.+PYTHONPATH="$source_dir" python3 - "$appdir" <<'PY'+import sys+from relocate import check_schema_paths+check_schema_paths(sys.argv[1])+PY+# Use the same patched native launcher as the artifact, not a shell stand-in.+# The unpatched executable corrupts GSETTINGS_SCHEMA_DIR after the hook runs.+install -m0755 "$apprun" "$appdir/AppRun.wrapped"+# Only the test copy needs a Nix interpreter to run in the build sandbox.+interpreter=$(patchelf --print-interpreter "$xkb_smoke")+patchelf --set-interpreter "$interpreter" --set-rpath "$(dirname "$interpreter")" "$appdir/AppRun.wrapped"+printf '[Desktop Entry]\nType=Application\nName=Runtime test\nExec=app\n' > "$appdir/Runtime.desktop"+printf '#!%s\nexec "$@"\n' "$BASH" > "$appdir/usr/bin/app"+chmod +x "$appdir/usr/bin/app"+# shellcheck disable=SC2016+printf '#!/usr/bin/env bash\nsource %q\nexec "$APPDIR/AppRun.wrapped" "$@"\n' "$hook" > "$appdir/AppRun"++# No user settings or session bus should be needed by these headless checks.+export GSETTINGS_BACKEND=memory XDG_CURRENT_DESKTOP=GNOME+export XDG_DATA_DIRS="$PWD/missing-system-data"++run_smokes() {+ env "$@" bash "$appdir/AppRun" "$xkb_smoke"+ for resolver in gnome libproxy; do+ env "$@" GIO_USE_PROXY_RESOLVER="$resolver" bash "$appdir/AppRun" "$settings_smoke"+ done+ env "$@" SSL_CERT_FILE="$ca_bundle" bash "$appdir/AppRun" "$tls_smoke"+ env "$@" SSL_CERT_FILE="$PWD/nonexistent-ca.pem" bash "$appdir/AppRun" "$tls_smoke" reject+}++# Fedora 44 dropped the old /etc/pki/tls/certs/ca-bundle.crt symlink.+# Exercise discovery against an isolated root with only its current location.+(+ export APPDIR="$appdir"+ # shellcheck disable=SC1090+ source "$hook"+ trust_root="$PWD/fedora-trust-root"+ mkdir -p "$trust_root/etc/pki/ca-trust/extracted/pem"+ cp "$ca_bundle" "$trust_root/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"+ test "$(macro_find_ca_bundle "$trust_root")" = "$trust_root/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"+)++# Normal AppImage startup supplies APPDIR; no caller workaround is necessary.+run_smokes -u XKB_CONFIG_ROOT -u GSETTINGS_SCHEMA_DIR APPDIR="$appdir"++# Relocating the bundle (including spaces) must override stale inherited paths.+mv "$appdir" "$PWD/Relocated Macro.AppDir"+appdir="$PWD/Relocated Macro.AppDir"+run_smokes XKB_CONFIG_ROOT="$PWD/missing-xkb-data" GSETTINGS_SCHEMA_DIR="$PWD/missing-schemas" APPDIR="$appdir"+# linuxdeploy's standalone AppRun also works without the runtime environment.+run_smokes -u APPDIR -u XKB_CONFIG_ROOT -u GSETTINGS_SCHEMA_DIRdiff --git a/nix/appimage/test_settings.c b/nix/appimage/test_settings.cnew file mode 100644index 0000000000..7ece5572d2--- /dev/null+++ b/nix/appimage/test_settings.c@@ -0,0 +1,81 @@+#define _GNU_SOURCE+#include <dlfcn.h>+#include <gio/gio.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++int main(void) {+ const char *root = getenv("GSETTINGS_SCHEMA_DIR");+ if (root == NULL) {+ fprintf(stderr, "Bundled GSETTINGS_SCHEMA_DIR is missing\n");+ return EXIT_FAILURE;+ }+ g_autoptr(GError) error = NULL;+ // No parent source: the host's installed schemas cannot satisfy this check.+ g_autoptr(GSettingsSchemaSource) source =+ g_settings_schema_source_new_from_directory(root, NULL, FALSE, &error);+ if (source == NULL) {+ fprintf(stderr, "Cannot load bundled schemas: %s\n", error->message);+ return EXIT_FAILURE;+ }++ const char *ids[] = {+ "org.gnome.system.proxy",+ "org.gnome.system.proxy.http",+ "org.gnome.system.proxy.https",+ "org.gnome.system.proxy.ftp",+ "org.gnome.system.proxy.socks",+ "org.gnome.desktop.interface",+ "org.gtk.Settings.FileChooser",+ };+ for (size_t i = 0; i < G_N_ELEMENTS(ids); i++) {+ g_autoptr(GSettingsSchema) schema =+ g_settings_schema_source_lookup(source, ids[i], FALSE);+ if (schema == NULL) {+ fprintf(stderr, "Missing bundled schema: %s\n", ids[i]);+ return EXIT_FAILURE;+ }+ g_autoptr(GSettings) settings = g_settings_new_full(schema, NULL, NULL);+ if (settings == NULL) {+ return EXIT_FAILURE;+ }+ }++ // Test both resolver routes, not just GIO's dummy resolver or XML presence.+ gboolean use_libproxy = g_strcmp0(g_getenv("GIO_USE_PROXY_RESOLVER"), "libproxy") == 0;+ const char *expected = use_libproxy ? "GLibproxyResolver" : "GProxyResolverGnome";+ GProxyResolver *resolver = g_proxy_resolver_get_default();+ if (strcmp(G_OBJECT_TYPE_NAME(resolver), expected) != 0) {+ fprintf(stderr, "Unexpected proxy resolver: %s\n", G_OBJECT_TYPE_NAME(resolver));+ return EXIT_FAILURE;+ }+ g_auto(GStrv) proxies = g_proxy_resolver_lookup(+ resolver, "https://example.invalid/", NULL, &error);+ if (proxies == NULL) {+ fprintf(stderr, "Proxy lookup failed: %s\n", error->message);+ return EXIT_FAILURE;+ }+ if (g_strv_length(proxies) != 1 || strcmp(proxies[0], "direct://") != 0) {+ fprintf(stderr, "Unexpected default proxy configuration\n");+ return EXIT_FAILURE;+ }+ if (use_libproxy) {+ // A store-backed libproxy would pass on NixOS while crashing in Fedora.+ // Check the actual loaded backend, not just the file we meant to copy.+ void *backend = dlopen("libpxbackend-1.0.so", RTLD_LAZY | RTLD_NOLOAD);+ Dl_info info = {0};+ g_autofree char *prefix = g_build_filename(g_getenv("APPDIR"), "usr/lib/", NULL);+ if (backend == NULL ||+ dladdr(dlsym(backend, "px_manager_get_type"), &info) == 0 ||+ !g_str_has_prefix(info.dli_fname, prefix)) {+ fprintf(stderr, "libproxy backend was not loaded from the AppDir\n");+ if (backend != NULL)+ dlclose(backend);+ return EXIT_FAILURE;+ }+ dlclose(backend);+ }+ printf("Bundled GTK/GNOME schemas and %s lookup succeeded: %s\n", expected, root);+ return EXIT_SUCCESS;+}diff --git a/nix/appimage/test_tls.c b/nix/appimage/test_tls.cnew file mode 100644index 0000000000..f423732840--- /dev/null+++ b/nix/appimage/test_tls.c@@ -0,0 +1,33 @@+#include <gio/gio.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++int main(int argc, char **argv) {+ GTlsBackend *backend = g_tls_backend_get_default();+ if (!g_tls_backend_supports_tls(backend)) {+ fprintf(stderr, "Bundled TLS backend was not loaded\n");+ return EXIT_FAILURE;+ }+ g_autoptr(GTlsDatabase) database = g_tls_backend_get_default_database(backend);+ if (argc == 2 && strcmp(argv[1], "reject") == 0) {+ if (database != NULL) {+ fprintf(stderr, "Invalid explicit CA bundle was not rejected\n");+ return EXIT_FAILURE;+ }+ puts("Invalid explicit CA bundle rejected (no fallback)");+ return EXIT_SUCCESS;+ }+ if (!G_IS_TLS_FILE_DATABASE(database)) {+ fprintf(stderr, "TLS backend did not use the explicit CA bundle\n");+ return EXIT_FAILURE;+ }+ g_autofree char *anchors = NULL;+ g_object_get(database, "anchors", &anchors, NULL);+ if (g_strcmp0(anchors, g_getenv("SSL_CERT_FILE")) != 0) {+ fprintf(stderr, "TLS backend changed the requested trust roots\n");+ return EXIT_FAILURE;+ }+ puts("Bundled TLS backend loaded the requested CA bundle");+ return EXIT_SUCCESS;+}diff --git a/nix/appimage/test_xdg.sh b/nix/appimage/test_xdg.shnew file mode 100755index 0000000000..d704b62828--- /dev/null+++ b/nix/appimage/test_xdg.sh@@ -0,0 +1,66 @@+#!/usr/bin/env bash+set -euo pipefail+helpers=${1:?usage: test_xdg.sh <portable-xdg-utils>}++# Help/version alone would miss the awk/sed/data paths used by real operations.+if grep -n /nix/store/ "$helpers/bin/xdg-open" "$helpers/bin/xdg-mime" "$helpers"/libexec/macro/*; then+ echo 'Desktop helpers still depend on the Nix store' >&2+ exit 1+fi++export HOME="$PWD/xdg-home" XDG_CONFIG_HOME="$PWD/xdg-config"+export XDG_DATA_HOME="$PWD/xdg-data" XDG_DATA_DIRS="$PWD/xdg-system-data"+unset DISPLAY WAYLAND_DISPLAY DESKTOP_SESSION KDE_FULL_SESSION GNOME_DESKTOP_SESSION_ID+export XDG_CURRENT_DESKTOP=X-Generic+mkdir -p "$HOME" "$XDG_CONFIG_HOME" "$XDG_DATA_HOME/applications" "$XDG_DATA_DIRS" "$PWD/fake-bin"+printf '[Desktop Entry]\nType=Application\nName=AppImage test\nExec=true\nMimeType=x-scheme-handler/macro-appimage-test;\n' \+ > "$XDG_DATA_HOME/applications/macro-appimage-test.desktop"++export PATH="$helpers/bin:$PATH"+bash "$helpers/bin/xdg-mime" --version+bash "$helpers/bin/xdg-open" --help >/dev/null+bash "$helpers/bin/xdg-mime" default macro-appimage-test.desktop x-scheme-handler/macro-appimage-test+test "$(bash "$helpers/bin/xdg-mime" query default x-scheme-handler/macro-appimage-test)" = macro-appimage-test.desktop++# Test browser dispatch without a display, session bus, network, or real browser.+# The generated script expands its arguments and log path when it runs.+# shellcheck disable=SC2016+printf '#!%s\n' "$BASH" > "$PWD/fake-bin/macro-test-browser"+# shellcheck disable=SC2016+printf '%s\n' '+set -eu+if [[ ${XDG_TEST_CHECK_ENV:-} == 1 ]]; then+ [[ $LD_LIBRARY_PATH == "$XDG_TEST_ORIGINAL_LD" ]]+ [[ -v SSL_CERT_FILE && -z $SSL_CERT_FILE ]]+ [[ ! -v GSETTINGS_SCHEMA_DIR && ! -v GIO_EXTRA_MODULES ]]+ [[ ! -v MACRO_APPIMAGE_HOST_ENV_CAPTURED && ! -v APPDIR && ! -v APPIMAGE ]]+fi+printf "%s\n" "$@" > "$XDG_TEST_BROWSER_LOG"+' >> "$PWD/fake-bin/macro-test-browser"+chmod +x "$PWD/fake-bin/macro-test-browser"+export PATH="$PWD/fake-bin:$PATH" BROWSER=macro-test-browser XDG_TEST_BROWSER_LOG="$PWD/browser-args"+url='https://example.invalid/appimage-test?a=1&b=2'+bash "$helpers/bin/xdg-open" "$url"+test "$(< "$XDG_TEST_BROWSER_LOG")" = "$url"++# Simulate a real AppRun call. Preserve caller values (including empty and+# unset), then ensure the external browser sees none of the bundle overrides.+appdir="$PWD/External helper AppDir"+mkdir -p "$appdir/usr"+cp -r "$helpers/." "$appdir/usr/"+(+ # shellcheck disable=SC1091+ source "$helpers/libexec/macro/host-environment.sh"+ unset GSETTINGS_SCHEMA_DIR GIO_EXTRA_MODULES+ export SSL_CERT_FILE=''+ export LD_LIBRARY_PATH="$PWD/original library path"+ export XDG_TEST_ORIGINAL_LD="$LD_LIBRARY_PATH" XDG_TEST_CHECK_ENV=1+ macro_capture_host_environment+ export APPDIR="$appdir" APPIMAGE="$PWD/test.AppImage"+ export LD_LIBRARY_PATH="$appdir/usr/lib" GIO_EXTRA_MODULES="$appdir/usr/lib/gio/modules"+ export GSETTINGS_SCHEMA_DIR="$appdir/usr/share/glib-2.0/schemas" SSL_CERT_FILE="$appdir/bundle-ca.pem"+ macro_capture_host_environment # Must not replace the original snapshot.+ bash "$appdir/usr/bin/xdg-open" "$url"+)+test "$(< "$XDG_TEST_BROWSER_LOG")" = "$url"+echo 'Portable desktop helpers registered/queried MIME handlers and launched a browser with its original environment'diff --git a/nix/appimage/test_xkb.c b/nix/appimage/test_xkb.cnew file mode 100644index 0000000000..751f271c98--- /dev/null+++ b/nix/appimage/test_xkb.c@@ -0,0 +1,37 @@+#include <stdio.h>+#include <stdlib.h>+#include <xkbcommon/xkbcommon.h>++int main(void) {+ const char *root = getenv("XKB_CONFIG_ROOT");+ struct xkb_context *context = xkb_context_new(+ XKB_CONTEXT_NO_DEFAULT_INCLUDES | XKB_CONTEXT_NO_ENVIRONMENT_NAMES);+ if (context == NULL) {+ return EXIT_FAILURE;+ }+ // Only the launcher's bundled directory may satisfy this test: no host or+ // Nix store include paths, even when they exist on the build machine.+ if (root == NULL || !xkb_context_include_path_append(context, root)) {+ fprintf(stderr, "Bundled XKB_CONFIG_ROOT is missing or unreadable\n");+ xkb_context_unref(context);+ return EXIT_FAILURE;+ }++ const char *layouts[] = {"us", "de"};+ for (size_t i = 0; i < sizeof(layouts) / sizeof(layouts[0]); i++) {+ struct xkb_rule_names names = {+ .rules = "evdev", .model = "pc105", .layout = layouts[i],+ };+ struct xkb_keymap *keymap = xkb_keymap_new_from_names(+ context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);+ if (keymap == NULL) {+ fprintf(stderr, "Cannot compile %s keymap from %s\n", layouts[i], root);+ xkb_context_unref(context);+ return EXIT_FAILURE;+ }+ xkb_keymap_unref(keymap);+ }+ printf("XKB keymaps compiled using only %s\n", root);+ xkb_context_unref(context);+ return EXIT_SUCCESS;+}diff --git a/nix/appimage/xdg-helper.sh b/nix/appimage/xdg-helper.shnew file mode 100755index 0000000000..5cdf820ea6--- /dev/null+++ b/nix/appimage/xdg-helper.sh@@ -0,0 +1,15 @@+#!/usr/bin/env bash+set -e+helper=${0##*/}+case "$helper" in xdg-open|xdg-mime) ;; *) exit 2;; esac+if [[ ${MACRO_APPIMAGE_HOST_ENV_CAPTURED:-} == 1 && -n ${APPDIR:-} ]]; then+ support_dir="$APPDIR/usr/libexec/macro"+else+ script=$(realpath "$0")+ support_dir="${script%/*}/../libexec/macro"+fi+# Host gio/browsers must not load the AppImage's GLib or its plugin directories.+# shellcheck disable=SC1091+source "$support_dir/host-environment.sh"+macro_restore_host_environment+exec "$support_dir/$helper" "$@"diff --git a/nix/tauri-desktop.nix b/nix/tauri-desktop.nixindex a1e8c4ad5c..03f26703ca 100644--- a/nix/tauri-desktop.nix+++ b/nix/tauri-desktop.nix@@ -60,6 +60,7 @@# WASM sources. Avoid recompiling both for AppImage-only changes.rel != "nix"&& !(lib.hasPrefix "nix/" rel)+ && !(lib.hasPrefix "nix-support/appimage-" rel)&& !(lib.hasPrefix "node_modules/" rel)&& !(lib.hasPrefix "apps/web/node_modules/" rel)&& !(lib.hasPrefix "apps/web/dist/" rel)@@ -311,10 +312,13 @@};tauriBundlerSource = pkgs.cargo-tauri.src;- tauriAppRun = pkgs.fetchurl {+ tauriAppRunSource = pkgs.fetchurl {url = "https://github.com/tauri-apps/binary-releases/releases/download/apprun-old/AppRun-x86_64";hash = "sha256-8wFApDoKWeRtshve/fdJuenyxpRukq+rus+YuK5z+08=";};+ tauriAppRun = pkgs.runCommand "tauri-apprun" { } ''+ ${pkgs.python3}/bin/python3 ${./appimage/patch_apprun.py} ${tauriAppRunSource} "$out"+ '';tauriLinuxdeployWrapper = pkgs.stdenv.mkDerivation {pname = "tauri-linuxdeploy-wrapper";version = "1";@@ -383,13 +387,13 @@return 1;}- char *hook_path = malloc(strlen(hooks_dir) + strlen("/macro-gio-tls.sh") + 2);+ char *hook_path = malloc(strlen(hooks_dir) + strlen("/00-macro-runtime.sh") + 2);if (hook_path == NULL) {perror("malloc TLS hook path");free(hooks_dir);return 1;}- sprintf(hook_path, "%s/macro-gio-tls.sh", hooks_dir);+ sprintf(hook_path, "%s/00-macro-runtime.sh", hooks_dir);FILE *hook = fopen(hook_path, "w");if (hook == NULL) {@@ -400,17 +404,7 @@}int failed = 0;- if (fputs("#! /usr/bin/env bash\n"- "export APPDIR=\"''${APPDIR:-\"$(dirname \"$(realpath \"$0\")\")\"}\"\n"- "export WEBKIT_INJECTED_BUNDLE_PATH=\"$APPDIR/usr/lib\"\n"- "gio_modules=\"$APPDIR/usr/lib/gio/modules\"\n"- "if [ -d \"$gio_modules\" ]; then\n"- " case \":''${GIO_EXTRA_MODULES:-}:\" in\n"- " *:\"$gio_modules\":*) ;;\n"- " *) export GIO_EXTRA_MODULES=\"$gio_modules''${GIO_EXTRA_MODULES:+:$GIO_EXTRA_MODULES}\" ;;\n"- " esac\n"- "fi\n",- hook) == EOF) {+ if (fputs(${builtins.toJSON (builtins.readFile ./appimage/runtime-hook.sh)}, hook) == EOF) {perror("write TLS hook");failed = 1;}@@ -461,9 +455,9 @@"--executable", "${pkgs.webkitgtk_4_1}/libexec/webkit2gtk-4.1/WebKitNetworkProcess","--executable", "${pkgs.webkitgtk_4_1}/libexec/webkit2gtk-4.1/WebKitGPUProcess","--library", "${pkgs.webkitgtk_4_1}/lib/webkit2gtk-4.1/injected-bundle/libwebkit2gtkinjectedbundle.so",- "--library", "${gioTlsModulePath}/libgiognutls.so",- "--library", "${gioTlsModulePath}/libgiognomeproxy.so",- "--library", "${gioTlsModulePath}/libgiolibproxy.so",+ "--library", "${appimageGioModulePath}/libgiognutls.so",+ "--library", "${appimageGioModulePath}/libgiognomeproxy.so",+ "--library", "${appimageGioModulePath}/libgiolibproxy.so",};size_t runtime_argc = sizeof(runtime_args) / sizeof(runtime_args[0]);char **args = calloc((size_t)argc + runtime_argc + 1, sizeof(char *));@@ -512,6 +506,11 @@version = "1-alpha-20250213-1";src = tauriLinuxdeployAppimagePluginSource;};+ tauriPortableLibproxy = pkgs.callPackage ../nix-support/appimage-libproxy.nix { };+ tauriPortableGlibNetworking = pkgs.callPackage ../nix-support/appimage-glib-networking.nix {+ libproxy = tauriPortableLibproxy;+ };+ appimageGioModulePath = "${tauriPortableGlibNetworking}/lib/gio/modules";tauriLinuxdeployAppimagePlugin = pkgs.stdenvNoCC.mkDerivation {pname = "linuxdeploy-plugin-appimage-patched";version = "1-alpha-20250213-1";@@ -534,6 +533,9 @@shiftdoneif [ -n "$appdir" ]; then+ # Same libproxy version/ABI and dependencies, but without nixpkgs'+ # hardcoded schema lookup. Replace the backend before ELF relocation.+ install -m0755 ${tauriPortableLibproxy}/lib/libproxy/libpxbackend-1.0.so "$appdir/usr/lib/libpxbackend-1.0.so"export PATH="${lib.makeBinPath [ pkgs.patchelf ]}:$PATH"${pkgs.python3}/bin/python3 ${./appimage/relocate.py} "$appdir"fi@@ -562,7 +564,7 @@pkgs.gst_all_1.gst-plugins-badpkgs.gst_all_1.gst-libavpkgs.openssl- pkgs.glib-networking+ tauriPortableGlibNetworking];tauriRuntimeLibraryPath = lib.makeLibraryPath tauriRuntimeLibraries;tauriRuntimeClosure = pkgs.closureInfo {@@ -581,6 +583,34 @@]);};+ # xkeyboard-config's compatibility path is a symlink. Tauri preserves+ # symlinks when copying directories, so stage a self-contained data tree.+ tauriXkbData = pkgs.runCommand "tauri-appimage-xkb-data" { } ''+ cp -rL ${pkgs.xkeyboard-config}/share/X11/xkb "$out"+ '';+ tauriXdgUtils = pkgs.callPackage ../nix-support/appimage-xdg-utils.nix { };+ tauriGsettingsSchemas =+ pkgs.runCommand "tauri-appimage-gsettings-schemas"+ {+ nativeBuildInputs = [ pkgs.glib.dev ];+ schemaDirs =+ lib.concatMapStringsSep " " (p: "${p}/share/gsettings-schemas/${p.name}/glib-2.0/schemas")+ [+ pkgs.gsettings-desktop-schemas+ pkgs.gtk3+ ];+ }+ ''+ mkdir -p "$out"+ shopt -s nullglob+ for schema_dir in $schemaDirs; do+ cp "$schema_dir/"*.xml "$out/"+ for override in "$schema_dir/"*.gschema.override; do+ cp "$override" "$out/"+ done+ done+ glib-compile-schemas --strict "$out"+ '';tauriAppImageConfig = builtins.toJSON {version = appVersion;plugins = desktopPlugins;@@ -594,12 +624,15 @@useLocalToolsDir = true;linux.appimage.bundleMediaFramework = true;linux.appimage.files = {- "/usr/bin/xdg-mime" = "${pkgs.xdg-utils}/bin/xdg-mime";- "/usr/bin/xdg-open" = "${pkgs.xdg-utils}/bin/xdg-open";- "/usr/lib/gio/modules/giomodule.cache" = "${pkgs.glib-networking}/lib/gio/modules/giomodule.cache";- "/usr/lib/gio/modules/libgiognomeproxy.so" = "${pkgs.glib-networking}/lib/gio/modules/libgiognomeproxy.so";- "/usr/lib/gio/modules/libgiognutls.so" = "${pkgs.glib-networking}/lib/gio/modules/libgiognutls.so";- "/usr/lib/gio/modules/libgiolibproxy.so" = "${pkgs.glib-networking}/lib/gio/modules/libgiolibproxy.so";+ "/usr/bin/xdg-mime" = "${tauriXdgUtils}/bin/xdg-mime";+ "/usr/bin/xdg-open" = "${tauriXdgUtils}/bin/xdg-open";+ "/usr/libexec/macro" = "${tauriXdgUtils}/libexec/macro";+ "/usr/share/X11/xkb" = "${tauriXkbData}";+ "/usr/share/glib-2.0/schemas" = "${tauriGsettingsSchemas}";+ "/usr/lib/gio/modules/giomodule.cache" = "${appimageGioModulePath}/giomodule.cache";+ "/usr/lib/gio/modules/libgiognomeproxy.so" = "${appimageGioModulePath}/libgiognomeproxy.so";+ "/usr/lib/gio/modules/libgiognutls.so" = "${appimageGioModulePath}/libgiognutls.so";+ "/usr/lib/gio/modules/libgiolibproxy.so" = "${appimageGioModulePath}/libgiolibproxy.so";};};};@@ -858,11 +891,20 @@pkgs.python3pkgs.patchelfpkgs.stdenv.cc+ pkgs.pkg-config+ ];+ buildInputs = [+ pkgs.libxkbcommon+ pkgs.glib];}''export PYTHONDONTWRITEBYTECODE=1python3 -m unittest discover -s ${./appimage} -v+ bash ${./appimage}/test_runtime.sh \+ ${tauriXkbData} ${tauriGsettingsSchemas} ${appimageGioModulePath} ${tauriAppRun} \+ ${tauriPortableLibproxy} ${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt+ bash ${./appimage}/test_xdg.sh ${tauriXdgUtils}# GStreamer's default Nix output is bin; its scanner and core plugins# live in the library output. Do not silently ship an empty helper dir.test -x ${lib.getLib pkgs.gst_all_1.gstreamer}/libexec/gstreamer-1.0/gst-plugin-scanner