···11+From 835eed6a2b975fba40c3ac18b4cf5429ba9d2836 Mon Sep 17 00:00:00 2001
22+From: Luna Nova <git@lunnova.dev>
33+Date: Wed, 7 Sep 2022 08:45:56 -0700
44+Subject: [PATCH] xdg-open: add $XDG_OPEN_USE_PORTAL env var
55+66+When set, the same mechanism that is used in a flatpak is used,
77+a dbus call to the portal. This is useful for distros with non-flatpak
88+wrapper or sandboxing features which require the same treatment, eg NixOS.
99+1010+See https://github.com/NixOS/nixpkgs/issues/160923
1111+---
1212+ scripts/xdg-open.in | 4 ++++
1313+ 1 file changed, 4 insertions(+)
1414+1515+diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
1616+index 8de839a..80d8fb3 100644
1717+--- a/scripts/xdg-open.in
1818++++ b/scripts/xdg-open.in
1919+@@ -508,6 +508,10 @@ if [ x"$DE" = x"" ]; then
2020+ DE=generic
2121+ fi
2222+2323++if [ -n "$NIXOS_XDG_OPEN_USE_PORTAL" ]; then
2424++ DE=flatpak
2525++fi
2626++
2727+ DEBUG 2 "Selected DE $DE"
2828+2929+ # sanitize BROWSER (avoid calling ourselves in particular)
+8-1
pkgs/tools/X11/xdg-utils/default.nix
···11{ lib, stdenv, fetchFromGitLab, fetchFromGitHub
22, file, libxslt, docbook_xml_dtd_412, docbook_xsl, xmlto
33, w3m, gnugrep, gnused, coreutils, xset, perlPackages
44-, mimiSupport ? false, gawk }:
44+, mimiSupport ? false, gawk
55+, withXdgOpenUsePortalPatch ? true }:
5667let
78 # A much better xdg-open
···2930 rev = "d11b33ec7f24cfb1546f6b459611d440013bdc72";
3031 sha256 = "sha256-8PtXfI8hRneEpnUvIV3M+6ACjlkx0w/NEiJFdGbbHnQ=";
3132 };
3333+3434+ patches = lib.optionals withXdgOpenUsePortalPatch [
3535+ # Allow forcing the use of XDG portals using NIXOS_XDG_OPEN_USE_PORTAL environment variable.
3636+ # Upstream PR: https://github.com/freedesktop/xdg-utils/pull/12
3737+ ./allow-forcing-portal-use.patch
3838+ ];
32393340 # just needed when built from git
3441 nativeBuildInputs = [ libxslt docbook_xml_dtd_412 docbook_xsl xmlto w3m ];