@@ -1,9 +1,17 @@
11{ config, lib, pkgs, ... }:
22
33with lib;
4+
5+let
6+ cfg = config.xdg.mime;
7+ associationOptions = with types; attrsOf (
8+ coercedTo (either (listOf str) str) (x: concatStringsSep ";" (toList x)) str
9+ );
10+in
11+
412{
513 meta = {
6− maintainers = teams.freedesktop.members;
14+ maintainers = teams.freedesktop.members ++ (with maintainers; [ figsoda ]);
715 };
816
917 options = {
@@ -16,9 +24,63 @@ with lib;
1624 <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html">XDG MIME Applications specification</link>.
1725 '';
1826 };
27+
28+ xdg.mime.addedAssociations = mkOption {
29+ type = associationOptions;
30+ default = {};
31+ example = {
32+ "application/pdf" = "firefox.desktop";
33+ "text/xml" = [ "nvim.desktop" "codium.desktop" ];
34+ };
35+ description = ''
36+ Adds associations between mimetypes and applications. See the
37+ <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations">
38+ specifications</link> for more information.
39+ '';
40+ };
41+
42+ xdg.mime.defaultApplications = mkOption {
43+ type = associationOptions;
44+ default = {};
45+ example = {
46+ "application/pdf" = "firefox.desktop";
47+ "image/png" = [ "sxiv.desktop" "gimp.desktop" ];
48+ };
49+ description = ''
50+ Sets the default applications for given mimetypes. See the
51+ <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#default">
52+ specifications</link> for more information.
53+ '';
54+ };
55+
56+ xdg.mime.removedAssociations = mkOption {
57+ type = associationOptions;
58+ default = {};
59+ example = {
60+ "audio/mp3" = [ "mpv.desktop" "umpv.desktop" ];
61+ "inode/directory" = "codium.desktop";
62+ };
63+ description = ''
64+ Removes associations between mimetypes and applications. See the
65+ <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations">
66+ specifications</link> for more information.
67+ '';
68+ };
1969 };
2070
21− config = mkIf config.xdg.mime.enable {
71+ config = mkIf cfg.enable {
72+ environment.etc."xdg/mimeapps.list" = mkIf (
73+ cfg.addedAssociations != {}
74+ || cfg.defaultApplications != {}
75+ || cfg.removedAssociations != {}
76+ ) {
77+ text = generators.toINI { } {
78+ "Added Associations" = cfg.addedAssociations;
79+ "Default Applications" = cfg.defaultApplications;
80+ "Removed Associations" = cfg.removedAssociations;
81+ };
82+ };
83+
2284 environment.pathsToLink = [ "/share/mime" ];
2385
2486 environment.systemPackages = [