summaryrefslogtreecommitdiff
path: root/home-manager/xdg-mime.nix
diff options
context:
space:
mode:
Diffstat (limited to 'home-manager/xdg-mime.nix')
-rw-r--r--home-manager/xdg-mime.nix37
1 files changed, 28 insertions, 9 deletions
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;
};
};