vuls: init at 0.27.0
[NixPkgs.git] / nixos / modules / config / xdg / mime.nix
blob9bd1af397002789124468206286d3f9b05abb1a0
1 { config, lib, pkgs, ... }:
2 let
3   cfg = config.xdg.mime;
4   associationOptions = with lib.types; attrsOf (
5     coercedTo (either (listOf str) str) (x: lib.concatStringsSep ";" (lib.toList x)) str
6   );
7 in
10   meta = {
11     maintainers = lib.teams.freedesktop.members ++ (with lib.maintainers; [ figsoda ]);
12   };
14   options = {
15     xdg.mime.enable = lib.mkOption {
16       type = lib.types.bool;
17       default = true;
18       description = ''
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).
22       '';
23     };
25     xdg.mime.addedAssociations = lib.mkOption {
26       type = associationOptions;
27       default = {};
28       example = {
29         "application/pdf" = "firefox.desktop";
30         "text/xml" = [ "nvim.desktop" "codium.desktop" ];
31       };
32       description = ''
33         Adds associations between mimetypes and applications. See the
34         [
35         specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
36       '';
37     };
39     xdg.mime.defaultApplications = lib.mkOption {
40       type = associationOptions;
41       default = {};
42       example = {
43         "application/pdf" = "firefox.desktop";
44         "image/png" = [ "sxiv.desktop" "gimp.desktop" ];
45       };
46       description = ''
47         Sets the default applications for given mimetypes. See the
48         [
49         specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#default) for more information.
50       '';
51     };
53     xdg.mime.removedAssociations = lib.mkOption {
54       type = associationOptions;
55       default = {};
56       example = {
57         "audio/mp3" = [ "mpv.desktop" "umpv.desktop" ];
58         "inode/directory" = "codium.desktop";
59       };
60       description = ''
61         Removes associations between mimetypes and applications. See the
62         [
63         specifications](https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations) for more information.
64       '';
65     };
66   };
68   config = lib.mkIf cfg.enable {
69     environment.etc."xdg/mimeapps.list" = lib.mkIf (
70       cfg.addedAssociations != {}
71       || cfg.defaultApplications != {}
72       || cfg.removedAssociations != {}
73     ) {
74       text = lib.generators.toINI { } {
75         "Added Associations" = cfg.addedAssociations;
76         "Default Applications" = cfg.defaultApplications;
77         "Removed Associations" = cfg.removedAssociations;
78       };
79     };
81     environment.pathsToLink = [ "/share/mime" ];
83     environment.systemPackages = [
84       # this package also installs some useful data, as well as its utilities
85       pkgs.shared-mime-info
86     ];
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
91       fi
93       if [ -w $out/share/applications ]; then
94           ${pkgs.buildPackages.desktop-file-utils}/bin/update-desktop-database $out/share/applications
95       fi
96     '';
97   };