python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / nixos / modules / config / xdg / mime.nix
blob3aa863083219ad869415516f5e89050a752b332f
1 { config, lib, pkgs, ... }:
3 with lib;
5 let
6   cfg = config.xdg.mime;
7   associationOptions = with types; attrsOf (
8     coercedTo (either (listOf str) str) (x: concatStringsSep ";" (toList x)) str
9   );
13   meta = {
14     maintainers = teams.freedesktop.members ++ (with maintainers; [ figsoda ]);
15   };
17   options = {
18     xdg.mime.enable = mkOption {
19       type = types.bool;
20       default = true;
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).
25       '';
26     };
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 = lib.mdDoc ''
36         Adds associations between mimetypes and applications. See the
37         [
38         specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
39       '';
40     };
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 = lib.mdDoc ''
50         Sets the default applications for given mimetypes. See the
51         [
52         specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#default) for more information.
53       '';
54     };
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 = lib.mdDoc ''
64         Removes associations between mimetypes and applications. See the
65         [
66         specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
67       '';
68     };
69   };
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     };
84     environment.pathsToLink = [ "/share/mime" ];
86     environment.systemPackages = [
87       # this package also installs some useful data, as well as its utilities
88       pkgs.shared-mime-info
89     ];
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
94       fi
96       if [ -w $out/share/applications ]; then
97           ${pkgs.buildPackages.desktop-file-utils}/bin/update-desktop-database $out/share/applications
98       fi
99     '';
100   };