summaryrefslogtreecommitdiff
path: root/home-manager
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2025-08-30 16:38:19 -0500
committerTim Keller <tjk@tjkeller.xyz>2025-08-30 16:38:19 -0500
commit5b5eb10c5985d21f5ae3a1d84ff3e3ecfce10ea5 (patch)
tree1ac56cc22a5add23f967823b32e7d78792640ff0 /home-manager
parent425cbb03ab00c8c25fd3cab160898188ea8ae57f (diff)
downloadnixos-5b5eb10c5985d21f5ae3a1d84ff3e3ecfce10ea5.tar.xz
nixos-5b5eb10c5985d21f5ae3a1d84ff3e3ecfce10ea5.zip
allow setting default application for generic categories of mime-types instead of the mimewiz like method
Diffstat (limited to 'home-manager')
-rw-r--r--home-manager/resources/xdg-mime/audio (renamed from home-manager/resources/xdg-mime/mpv)55
-rw-r--r--home-manager/resources/xdg-mime/email (renamed from home-manager/resources/xdg-mime/thunderbird)3
-rw-r--r--home-manager/resources/xdg-mime/image (renamed from home-manager/resources/xdg-mime/sxiv)0
-rw-r--r--home-manager/resources/xdg-mime/pdf (renamed from home-manager/resources/xdg-mime/org.pwmt.zathura-pdf-mupdf)0
-rw-r--r--home-manager/resources/xdg-mime/text (renamed from home-manager/resources/xdg-mime/nvim)0
-rw-r--r--home-manager/resources/xdg-mime/video55
-rw-r--r--home-manager/xdg-mime.nix37
7 files changed, 86 insertions, 64 deletions
diff --git a/home-manager/resources/xdg-mime/mpv b/home-manager/resources/xdg-mime/audio
index 697e71b..fd00b26 100644
--- a/home-manager/resources/xdg-mime/mpv
+++ b/home-manager/resources/xdg-mime/audio
@@ -1,24 +1,7 @@
-application/mxf
-application/ogg
-application/sdp
-application/smil
-application/streamingmedia
-application/vnd.apple.mpegurl
-application/vnd.ms-asf
-application/vnd.rn-realmedia
-application/vnd.rn-realmedia-vbr
application/x-cue
application/x-extension-m4a
-application/x-extension-mp4
-application/x-matroska
-application/x-mpegurl
-application/x-ogg
-application/x-ogm
application/x-ogm-audio
-application/x-ogm-video
application/x-shorten
-application/x-smil
-application/x-streamingmedia
audio/3gpp
audio/3gpp2
audio/AMR
@@ -80,41 +63,3 @@ audio/x-vorbis
audio/x-vorbis+ogg
audio/x-wav
audio/x-wavpack
-video/3gp
-video/3gpp
-video/3gpp2
-video/avi
-video/divx
-video/dv
-video/fli
-video/flv
-video/mkv
-video/mp2t
-video/mp4
-video/mp4v-es
-video/mpeg
-video/msvideo
-video/ogg
-video/quicktime
-video/vnd.divx
-video/vnd.mpegurl
-video/vnd.rn-realvideo
-video/webm
-video/x-avi
-video/x-flc
-video/x-flic
-video/x-flv
-video/x-m4v
-video/x-matroska
-video/x-mpeg2
-video/x-mpeg3
-video/x-ms-afs
-video/x-ms-asf
-video/x-ms-wmv
-video/x-ms-wmx
-video/x-ms-wvxvideo
-video/x-msvideo
-video/x-ogm
-video/x-ogm+ogg
-video/x-theora
-video/x-theora+ogg
diff --git a/home-manager/resources/xdg-mime/thunderbird b/home-manager/resources/xdg-mime/email
index adbec40..db65256 100644
--- a/home-manager/resources/xdg-mime/thunderbird
+++ b/home-manager/resources/xdg-mime/email
@@ -1,3 +1,6 @@
+application/mbox
+application/vnd.ms-outlook
message/rfc822
+text/calendar
x-scheme-handler/mailto
x-scheme-handler/mid
diff --git a/home-manager/resources/xdg-mime/sxiv b/home-manager/resources/xdg-mime/image
index 4401ebb..4401ebb 100644
--- a/home-manager/resources/xdg-mime/sxiv
+++ b/home-manager/resources/xdg-mime/image
diff --git a/home-manager/resources/xdg-mime/org.pwmt.zathura-pdf-mupdf b/home-manager/resources/xdg-mime/pdf
index 73bd5d0..73bd5d0 100644
--- a/home-manager/resources/xdg-mime/org.pwmt.zathura-pdf-mupdf
+++ b/home-manager/resources/xdg-mime/pdf
diff --git a/home-manager/resources/xdg-mime/nvim b/home-manager/resources/xdg-mime/text
index 709cb57..709cb57 100644
--- a/home-manager/resources/xdg-mime/nvim
+++ b/home-manager/resources/xdg-mime/text
diff --git a/home-manager/resources/xdg-mime/video b/home-manager/resources/xdg-mime/video
new file mode 100644
index 0000000..6a0839e
--- /dev/null
+++ b/home-manager/resources/xdg-mime/video
@@ -0,0 +1,55 @@
+application/mxf
+application/ogg
+application/sdp
+application/smil
+application/streamingmedia
+application/vnd.apple.mpegurl
+application/vnd.ms-asf
+application/vnd.rn-realmedia
+application/vnd.rn-realmedia-vbr
+application/x-extension-mp4
+application/x-matroska
+application/x-mpegurl
+application/x-ogg
+application/x-ogm
+application/x-ogm-video
+application/x-smil
+application/x-streamingmedia
+video/3gp
+video/3gpp
+video/3gpp2
+video/avi
+video/divx
+video/dv
+video/fli
+video/flv
+video/mkv
+video/mp2t
+video/mp4
+video/mp4v-es
+video/mpeg
+video/msvideo
+video/ogg
+video/quicktime
+video/vnd.divx
+video/vnd.mpegurl
+video/vnd.rn-realvideo
+video/webm
+video/x-avi
+video/x-flc
+video/x-flic
+video/x-flv
+video/x-m4v
+video/x-matroska
+video/x-mpeg2
+video/x-mpeg3
+video/x-ms-afs
+video/x-ms-asf
+video/x-ms-wmv
+video/x-ms-wmx
+video/x-ms-wvxvideo
+video/x-msvideo
+video/x-ogm
+video/x-ogm+ogg
+video/x-theora
+video/x-theora+ogg
diff --git a/home-manager/xdg-mime.nix b/home-manager/xdg-mime.nix
index 043b214..420510f 100644
--- a/home-manager/xdg-mime.nix
+++ b/home-manager/xdg-mime.nix
@@ -1,22 +1,41 @@
{ config, lib, pkgs, ... }: let
- cfg = config.xdg.mimeApps._setDefaultApplications;
- mimeDir = ./resources/xdg-mime;
+ cfg = config.xdg.mimeApps._defaultCategoryApplications;
- getApplicationMimeTypes = applicationName: lib.filter (s: s != "") (lib.splitString "\n" (builtins.readFile "${mimeDir}/${applicationName}"));
+ # Mime-type category files are stored here
+ mimeResources = ./resources/xdg-mime;
- getMimeTypeApplicationList = applicationName: lib.mkMerge (lib.map (mimetype:
- { "${mimetype}" = [ "${applicationName}.desktop" ]; }
- ) (getApplicationMimeTypes applicationName));
+ # Files present in mimeResources with newline separated mime-types
+ # Would be more fun to load these dynamically with builtins.readDir, but I will be disciplined
+ categories = [ "audio" "email" "image" "pdf" "text" "video" ];
- defaultApplications = lib.mkMerge (lib.mapAttrsToList (appPath: pathType: lib.mkIf (pathType == "regular") (getMimeTypeApplicationList appPath)) (builtins.readDir mimeDir));
+ # Dynamically generate categories
+ categoryApplications = (lib.genAttrs categories (category: lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [ ];
+ description = "set the default application used for ${category} files. omit '.desktop'";
+ }));
+
+ # Create list of mime-types from the category file
+ getCategoryMimeTypes = category: lib.filter (s: s != "") (lib.splitString "\n" (builtins.readFile "${mimeResources}/${category}"));
+
+ # Structure default applications for a specified category how home-manager expects
+ assignMimeTypes = applications: category: lib.map (mimetype:
+ { "${mimetype}" = lib.mkIf (applications != []) (lib.map (app: "${app}.desktop") applications); }
+ ) (getCategoryMimeTypes category);
+
+ # Combine all category applications
+ defaultApplications = lib.mkMerge (lib.flatten (
+ lib.map (category: assignMimeTypes cfg.categoryApplications.${category} category) categories
+ ));
in {
- options.xdg.mimeApps._setDefaultApplications = {
+ options.xdg.mimeApps._defaultCategoryApplications = {
enable = lib.mkEnableOption "set default applications as defined in the resources dir";
+ inherit categoryApplications;
};
config = lib.mkIf cfg.enable {
xdg.mimeApps = {
- enable = true;
+ enable = lib.mkDefault true;
inherit defaultApplications;
};
};