1 { config, lib, pkgs, ... }:
7 associationOptions = with types; attrsOf (
8 coercedTo (either (listOf str) str) (x: concatStringsSep ";" (toList x)) str
14 maintainers = teams.freedesktop.members ++ (with maintainers; [ figsoda ]);
18 xdg.mime.enable = mkOption {
21 description = lib.mdDoc ''
22 Whether to install files to support the
23 [XDG Shared MIME-info specification](https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html) and the
24 [XDG MIME Applications specification](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html).
28 xdg.mime.addedAssociations = mkOption {
29 type = associationOptions;
32 "application/pdf" = "firefox.desktop";
33 "text/xml" = [ "nvim.desktop" "codium.desktop" ];
35 description = lib.mdDoc ''
36 Adds associations between mimetypes and applications. See the
38 specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
42 xdg.mime.defaultApplications = mkOption {
43 type = associationOptions;
46 "application/pdf" = "firefox.desktop";
47 "image/png" = [ "sxiv.desktop" "gimp.desktop" ];
49 description = lib.mdDoc ''
50 Sets the default applications for given mimetypes. See the
52 specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#default) for more information.
56 xdg.mime.removedAssociations = mkOption {
57 type = associationOptions;
60 "audio/mp3" = [ "mpv.desktop" "umpv.desktop" ];
61 "inode/directory" = "codium.desktop";
63 description = lib.mdDoc ''
64 Removes associations between mimetypes and applications. See the
66 specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
71 config = mkIf cfg.enable {
72 environment.etc."xdg/mimeapps.list" = mkIf (
73 cfg.addedAssociations != {}
74 || cfg.defaultApplications != {}
75 || cfg.removedAssociations != {}
77 text = generators.toINI { } {
78 "Added Associations" = cfg.addedAssociations;
79 "Default Applications" = cfg.defaultApplications;
80 "Removed Associations" = cfg.removedAssociations;
84 environment.pathsToLink = [ "/share/mime" ];
86 environment.systemPackages = [
87 # this package also installs some useful data, as well as its utilities
91 environment.extraSetup = ''
92 if [ -w $out/share/mime ] && [ -d $out/share/mime/packages ]; then
93 XDG_DATA_DIRS=$out/share PKGSYSTEM_ENABLE_FSYNC=0 ${pkgs.buildPackages.shared-mime-info}/bin/update-mime-database -V $out/share/mime > /dev/null
96 if [ -w $out/share/applications ]; then
97 ${pkgs.buildPackages.desktop-file-utils}/bin/update-desktop-database $out/share/applications