From 0b7fd187e2dc8364cf31ed69347e4793c2d83a57 Mon Sep 17 00:00:00 2001
From: Tom Wieczorek <tom@bibbu.net>
Date: Tue, 26 Jul 2022 10:08:25 +0200
Subject: [PATCH] xdg-mime-apps: fix regex in `mimeAssociations`

The XDG Desktop Entry spec mentions that multiple values per key may be
optionally terminated by a semicolon. An example for this is the Firefox
desktop file, which has no trailing semicolon. This breaks the sed regex
used in `mimeAssociations`.

Fix the regex by matching the end of string, optionally preceded by a
semicolon, or any other semicolon. This makes it work with both
semicolon-terminated and non-semicolon-terminated desktop files.
---
 modules/misc/xdg-mime-apps.nix | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/misc/xdg-mime-apps.nix b/modules/misc/xdg-mime-apps.nix
index cda9bd19b..2093caa2d 100644
--- a/modules/misc/xdg-mime-apps.nix
+++ b/modules/misc/xdg-mime-apps.nix
@@ -94,7 +94,7 @@ in {
             for p in $ps ; do
               for path in "$p"/share/applications/*.desktop ; do
                 name="''${path##*/}"
-                sed -n "/^MimeType=/ { s/.*=//; s/;/;$name\n/g; p; }" "$path"
+                sed -n -E "/^MimeType=/ { s/.*=//; s/;?$|;/;$name\n/g; p; }" "$path"
               done
             done > "$out"
           '';