git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/xdg/mime: add config for associations

between mimetypes and applications

commitec2690c67f4f7d591d8ec037c4defb876eb9bf84 authorfigsoda <figsoda@pm.me> dateSun 12 Sep 2021, 21:02 (5 years ago) parent2424ff5
3 files changed+79−2
nixos/doc/manual/from_md/release-notes/rl-2111.section.xml+13 nixos/doc/manual/release-notes/rl-2111.section.md+2 nixos/modules/config/xdg/mime.nix+64−2
nixos/doc/manual/from_md/release-notes/rl-2111.section.xml+13
@@ -1170,6 +1170,19 @@ Superuser created successfully.
11701170 directories, thus increasing the purity of the build.
11711171 </para>
11721172 </listitem>
1173+ <listitem>
1174+ <para>
1175+ Three new options,
1176+ <link linkend="opt-xdg.mime.addedAssociations">xdg.mime.addedAssociations</link>,
1177+ <link linkend="opt-xdg.mime.defaultApplications">xdg.mime.defaultApplications</link>,
1178+ and
1179+ <link linkend="opt-xdg.mime.removedAssociations">xdg.mime.removedAssociations</link>
1180+ have been added to the
1181+ <link linkend="opt-xdg.mime.enable">xdg.mime</link> module to
1182+ allow the configuration of
1183+ <literal>/etc/xdg/mimeapps.list</literal>.
1184+ </para>
1185+ </listitem>
11731186 </itemizedlist>
11741187 </section>
11751188</section>
nixos/doc/manual/release-notes/rl-2111.section.md+2
@@ -336,3 +336,5 @@ To be able to access the web UI this port needs to be opened in the firewall.
336336
337337- `lua` and `luajit` interpreters have been patched to avoid looking into /usr/lib
338338 directories, thus increasing the purity of the build.
339+
340+- Three new options, [xdg.mime.addedAssociations](#opt-xdg.mime.addedAssociations), [xdg.mime.defaultApplications](#opt-xdg.mime.defaultApplications), and [xdg.mime.removedAssociations](#opt-xdg.mime.removedAssociations) have been added to the [xdg.mime](#opt-xdg.mime.enable) module to allow the configuration of `/etc/xdg/mimeapps.list`.
nixos/modules/config/xdg/mime.nix+64−2
@@ -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 = [