2023-07-15 08:44:18 +00:00
|
|
|
{ config, lib, ...}:
|
2023-01-28 09:22:11 +00:00
|
|
|
|
2023-07-15 10:04:22 +00:00
|
|
|
let
|
|
|
|
# ProgramConfig -> { "<mime-type>" = { priority, desktop }; }
|
|
|
|
weightedMimes = prog: builtins.mapAttrs (_key: desktop: { priority = prog.mime.priority; desktop = desktop; }) prog.mime.associations;
|
|
|
|
# [ { "<mime-type>" = { priority, desktop } ]; } ] -> { "<mime-type>" = [ { priority, desktop } ... ]; }
|
|
|
|
mergeMimes = mimes: lib.foldAttrs (item: acc: [item] ++ acc) [] mimes;
|
|
|
|
# [ { priority, desktop } ... ] -> Self
|
|
|
|
sortOneMimeType = associations: builtins.sort (l: r: assert l.priority != r.priority; l.priority < r.priority) associations;
|
|
|
|
sortMimes = mimes: builtins.mapAttrs (_k: sortOneMimeType) mimes;
|
|
|
|
removePriorities = mimes: builtins.mapAttrs (_k: associations: builtins.map (a: a.desktop) associations) mimes;
|
|
|
|
|
|
|
|
# [ ProgramConfig ]
|
|
|
|
enabledPrograms = builtins.filter (p: p.enabled) (builtins.attrValues config.sane.programs);
|
|
|
|
# [ { "<mime-type>" = { prority, desktop } ]
|
|
|
|
enabledWeightedMimes = builtins.map weightedMimes enabledPrograms;
|
|
|
|
in
|
2023-01-28 09:22:11 +00:00
|
|
|
{
|
|
|
|
# the xdg mime type for a file can be found with:
|
|
|
|
# - `xdg-mime query filetype path/to/thing.ext`
|
2023-07-16 12:17:54 +00:00
|
|
|
# the default handler for a mime type can be found with:
|
|
|
|
# - `xdg-mime query default <mimetype>` (e.g. x-scheme-handler/http)
|
|
|
|
#
|
2023-01-28 09:26:29 +00:00
|
|
|
# we can have single associations or a list of associations.
|
|
|
|
# there's also options to *remove* [non-default] associations from specific apps
|
2023-01-28 09:22:11 +00:00
|
|
|
xdg.mime.enable = true;
|
2023-07-15 10:04:22 +00:00
|
|
|
xdg.mime.defaultApplications = removePriorities (sortMimes (mergeMimes enabledWeightedMimes));
|
2023-01-28 09:22:11 +00:00
|
|
|
}
|