summary refs log tree commit diff
path: root/nixos/modules/config
diff options
context:
space:
mode:
authorfigsoda <figsoda@pm.me>2021-09-12 21:02:40 -0400
committerfigsoda <figsoda@pm.me>2021-09-12 21:02:40 -0400
commitec2690c67f4f7d591d8ec037c4defb876eb9bf84 (patch)
treef0dd96125d3e36823ff09a29c3bb880c7e8504d6 /nixos/modules/config
parent2424ff5e4c2908d01d34292ed446e673f5a5f638 (diff)
downloadnixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.tar
nixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.tar.gz
nixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.tar.bz2
nixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.tar.lz
nixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.tar.xz
nixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.tar.zst
nixpkgs-ec2690c67f4f7d591d8ec037c4defb876eb9bf84.zip
nixos/xdg/mime: add config for associations
between mimetypes and applications
Diffstat (limited to 'nixos/modules/config')
-rw-r--r--nixos/modules/config/xdg/mime.nix66
1 files changed, 64 insertions, 2 deletions
diff --git a/nixos/modules/config/xdg/mime.nix b/nixos/modules/config/xdg/mime.nix
index 4cdb3f30994..9b6dd4cab5f 100644
--- a/nixos/modules/config/xdg/mime.nix
+++ b/nixos/modules/config/xdg/mime.nix
@@ -1,9 +1,17 @@
 { config, lib, pkgs, ... }:
 
 with lib;
+
+let
+  cfg = config.xdg.mime;
+  associationOptions = with types; attrsOf (
+    coercedTo (either (listOf str) str) (x: concatStringsSep ";" (toList x)) str
+  );
+in
+
 {
   meta = {
-    maintainers = teams.freedesktop.members;
+    maintainers = teams.freedesktop.members ++ (with maintainers; [ figsoda ]);
   };
 
   options = {
@@ -16,9 +24,63 @@ with lib;
         <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html">XDG MIME Applications specification</link>.
       '';
     };
+
+    xdg.mime.addedAssociations = mkOption {
+      type = associationOptions;
+      default = {};
+      example = {
+        "application/pdf" = "firefox.desktop";
+        "text/xml" = [ "nvim.desktop" "codium.desktop" ];
+      };
+      description = ''
+        Adds associations between mimetypes and applications. See the
+        <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations">
+        specifications</link> for more information.
+      '';
+    };
+
+    xdg.mime.defaultApplications = mkOption {
+      type = associationOptions;
+      default = {};
+      example = {
+        "application/pdf" = "firefox.desktop";
+        "image/png" = [ "sxiv.desktop" "gimp.desktop" ];
+      };
+      description = ''
+        Sets the default applications for given mimetypes. See the
+        <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#default">
+        specifications</link> for more information.
+      '';
+    };
+
+    xdg.mime.removedAssociations = mkOption {
+      type = associationOptions;
+      default = {};
+      example = {
+        "audio/mp3" = [ "mpv.desktop" "umpv.desktop" ];
+        "inode/directory" = "codium.desktop";
+      };
+      description = ''
+        Removes associations between mimetypes and applications. See the
+        <link xlink:href="https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html#associations">
+        specifications</link> for more information.
+      '';
+    };
   };
 
-  config = mkIf config.xdg.mime.enable {
+  config = mkIf cfg.enable {
+    environment.etc."xdg/mimeapps.list" = mkIf (
+      cfg.addedAssociations != {}
+      || cfg.defaultApplications != {}
+      || cfg.removedAssociations != {}
+    ) {
+      text = generators.toINI { } {
+        "Added Associations" = cfg.addedAssociations;
+        "Default Applications" = cfg.defaultApplications;
+        "Removed Associations" = cfg.removedAssociations;
+      };
+    };
+
     environment.pathsToLink = [ "/share/mime" ];
 
     environment.systemPackages = [