diff --git a/pkgs/development/libraries/xdg-desktop-portal/default.nix b/pkgs/development/libraries/xdg-desktop-portal/default.nix
index 05b0f5534481..438940f3bac6 100644
--- a/pkgs/development/libraries/xdg-desktop-portal/default.nix
+++ b/pkgs/development/libraries/xdg-desktop-portal/default.nix
@@ -3,9 +3,9 @@
 , autoreconfHook
 , dbus
 , fetchFromGitHub
-, fetchpatch
 , flatpak
 , fuse3
+, bubblewrap
 , systemdMinimal
 , geoclue2
 , glib
@@ -20,12 +20,12 @@
 , python3
 , pkg-config
 , stdenv
-, substituteAll
+, runCommand
 , wrapGAppsHook
 , enableGeoLocation ? true
 }:
 
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
   pname = "xdg-desktop-portal";
   version = "1.15.0";
 
@@ -33,11 +33,21 @@ stdenv.mkDerivation rec {
 
   src = fetchFromGitHub {
     owner = "flatpak";
-    repo = pname;
-    rev = version;
+    repo = "xdg-desktop-portal";
+    rev = finalAttrs.version;
     sha256 = "sha256-Kw3zJeGwPfw1fDo8HsgYmrpgCk/PUvWZPRloKJNAJVc=";
   };
 
+  patches = [
+    # The icon validator copied from Flatpak needs to access the gdk-pixbuf loaders
+    # in the Nix store and cannot bind FHS paths since those are not available on NixOS.
+    (runCommand "icon-validator.patch" { } ''
+      # Flatpak uses a different path
+      substitute "${flatpak.icon-validator-patch}" "$out" \
+        --replace "/icon-validator/validate-icon.c" "/src/validate-icon.c"
+    '')
+  ];
+
   nativeBuildInputs = [
     autoreconfHook
     libxml2
@@ -50,6 +60,7 @@ stdenv.mkDerivation rec {
     dbus
     flatpak
     fuse3
+    bubblewrap
     systemdMinimal # libsystemd
     glib
     gsettings-desktop-schemas
@@ -83,6 +94,11 @@ stdenv.mkDerivation rec {
   passthru = {
     tests = {
       installedTests = nixosTests.installed-tests.xdg-desktop-portal;
+
+      validate-icon = runCommand "test-icon-validation" { } ''
+        ${finalAttrs.finalPackage}/libexec/xdg-desktop-portal-validate-icon --sandbox 512 512 ${../../../applications/audio/zynaddsubfx/ZynLogo.svg} > "$out"
+        grep format=svg "$out"
+      '';
     };
   };
 
@@ -92,4 +108,4 @@ stdenv.mkDerivation rec {
     maintainers = with maintainers; [ jtojnar ];
     platforms = platforms.linux;
   };
-}
+})