2024-08-29 05:00:20 +00:00
|
|
|
{ lib, writeTextFile }:
|
|
|
|
|
|
|
|
/* Create an XDG MIME Association listing. This should also take care of
|
|
|
|
generating desktop-specific mimeapps.list if `desktopName` is given. The
|
|
|
|
given desktop name is already assumed to be in suitable casing which is
|
|
|
|
typically in lowercase ASCII.
|
|
|
|
*/
|
|
|
|
{
|
2025-01-12 09:57:14 +00:00
|
|
|
# An optional string containing the name of the desktop to be associated
|
|
|
|
# with.
|
|
|
|
desktopName ? "",
|
2024-08-29 05:00:20 +00:00
|
|
|
|
2025-01-12 09:57:14 +00:00
|
|
|
# Applications to be put in `Added Associations`. This is not set when the
|
|
|
|
# database is desktop-specific (when the `desktopName` is non-empty.)
|
|
|
|
addedAssociations ? { },
|
2024-08-29 05:00:20 +00:00
|
|
|
|
2025-01-12 09:57:14 +00:00
|
|
|
# Associations to be put in `Removed Associations` in the file. Similar to
|
|
|
|
# `addedAssociations`, this will not be added when it is desktop-specific.
|
|
|
|
removedAssociations ? { },
|
2024-08-29 05:00:20 +00:00
|
|
|
|
2025-01-12 09:57:14 +00:00
|
|
|
# Set of applications to be opened associated with the MIME type.
|
|
|
|
defaultApplications ? { }, }:
|
2024-08-29 05:00:20 +00:00
|
|
|
|
|
|
|
writeTextFile {
|
2025-01-12 09:57:14 +00:00
|
|
|
name = "xdg-mime-associations${
|
|
|
|
lib.optionalString (desktopName != "") "-${desktopName}"
|
|
|
|
}";
|
2024-08-29 05:00:20 +00:00
|
|
|
text =
|
|
|
|
# Non-desktop-specific mimeapps.list are only allowed to specify
|
|
|
|
# default applications.
|
|
|
|
lib.generators.toINI { } ({
|
|
|
|
"Default Applications" = defaultApplications;
|
|
|
|
} // (lib.optionalAttrs (desktopName == "") {
|
|
|
|
"Added Associations" = addedAssociations;
|
|
|
|
"Removed Associations" = removedAssociations;
|
|
|
|
}));
|
2025-01-12 09:57:14 +00:00
|
|
|
destination = "/share/applications/${
|
|
|
|
lib.optionalString (desktopName != "") "${desktopName}-"
|
|
|
|
}mimeapps.list";
|
2024-08-29 05:00:20 +00:00
|
|
|
}
|
|
|
|
|