1 { config, lib, pkgs, ... }:
4 associationOptions = with lib.types; attrsOf (
5 coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str
11 maintainers = lib.teams.freedesktop.members ++ (with lib.maintainers; [ figsoda ]);
15 xdg.mime.enable = lib.mkOption {
16 type = lib.types.bool;
19 Whether to install files to support the
20 [XDG Shared MIME-info specification](https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html) and the
21 [XDG MIME Applications specification](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html).
25 xdg.mime.addedAssociations = lib.mkOption {
26 type = associationOptions;
29 "application/pdf" = "firefox.desktop";
30 "text/xml" = [ "nvim.desktop" "codium.desktop" ];
33 Adds associations between mimetypes and applications. See the
35 specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
39 xdg.mime.defaultApplications = lib.mkOption {
40 type = associationOptions;
43 "application/pdf" = "firefox.desktop";
44 "image/png" = [ "sxiv.desktop" "gimp.desktop" ];
47 Sets the default applications for given mimetypes. See the
49 specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#default) for more information.
53 xdg.mime.removedAssociations = lib.mkOption {
54 type = associationOptions;
57 "audio/mp3" = [ "mpv.desktop" "umpv.desktop" ];
58 "inode/directory" = "codium.desktop";
61 Removes associations between mimetypes and applications. See the
63 specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
68 config = lib.mkIf cfg.enable {
69 environment.etc."xdg/mimeapps.list" = lib.mkIf (
70 cfg.addedAssociations != {}
71 || cfg.defaultApplications != {}
72 || cfg.removedAssociations != {}
74 text = lib.generators.toINI { } {
75 "Added Associations" = cfg.addedAssociations;
76 "Default Applications" = cfg.defaultApplications;
77 "Removed Associations" = cfg.removedAssociations;
81 environment.pathsToLink = [ "/share/mime" ];
83 environment.systemPackages = [
84 # this package also installs some useful data, as well as its utilities
88 environment.extraSetup = ''
89 if [ -w $out/share/mime ] && [ -d $out/share/mime/packages ]; then
90 XDG_DATA_DIRS=$out/share PKGSYSTEM_ENABLE_FSYNC=0 ${pkgs.buildPackages.shared-mime-info}/bin/update-mime-database -V $out/share/mime > /dev/null
93 if [ -w $out/share/applications ]; then
94 ${pkgs.buildPackages.desktop-file-utils}/bin/update-desktop-database $out/share/applications