2019-09-05 09:25:31 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xdg.mimeApps;
|
|
|
|
|
|
|
|
strListOrSingleton = with types;
|
|
|
|
coercedTo (either (listOf str) str) toList (listOf str);
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2019-09-05 09:25:31 +00:00
|
|
|
meta.maintainers = with maintainers; [ pacien ];
|
|
|
|
|
|
|
|
options.xdg.mimeApps = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to manage <filename>$XDG_CONFIG_HOME/mimeapps.list</filename>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The generated file is read-only.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# descriptions from
|
|
|
|
# https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.1.html
|
|
|
|
|
|
|
|
associations.added = mkOption {
|
|
|
|
type = types.attrsOf strListOrSingleton;
|
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2019-09-05 09:25:31 +00:00
|
|
|
{
|
|
|
|
"mimetype1" = [ "foo1.desktop" "foo2.desktop" "foo3.desktop" ];
|
|
|
|
"mimetype2" = "foo4.desktop";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Defines additional associations of applications with
|
|
|
|
mimetypes, as if the .desktop file was listing this mimetype
|
|
|
|
in the first place.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
associations.removed = mkOption {
|
|
|
|
type = types.attrsOf strListOrSingleton;
|
|
|
|
default = { };
|
|
|
|
example = { "mimetype1" = "foo5.desktop"; };
|
|
|
|
description = ''
|
|
|
|
Removes associations of applications with mimetypes, as if the
|
|
|
|
.desktop file was <emphasis>not</emphasis> listing this
|
|
|
|
mimetype in the first place.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultApplications = mkOption {
|
|
|
|
type = types.attrsOf strListOrSingleton;
|
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2019-09-05 09:25:31 +00:00
|
|
|
{
|
|
|
|
"mimetype1" = [ "default1.desktop" "default2.desktop" ];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
The default application to be used for a given mimetype. This
|
|
|
|
is, for instance, the one that will be started when
|
|
|
|
double-clicking on a file in a file manager. If the
|
|
|
|
application is no longer installed, the next application in
|
|
|
|
the list is attempted, and so on.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 21:24:27 +00:00
|
|
|
assertions =
|
|
|
|
[ (hm.assertions.assertPlatform "xdg.mimeApps" pkgs platforms.linux) ];
|
|
|
|
|
2019-09-20 18:00:25 +00:00
|
|
|
# Deprecated but still used by some applications.
|
2020-05-09 21:53:48 +00:00
|
|
|
xdg.dataFile."applications/mimeapps.list".source =
|
2019-09-20 18:00:25 +00:00
|
|
|
config.xdg.configFile."mimeapps.list".source;
|
|
|
|
|
2019-09-05 09:25:31 +00:00
|
|
|
xdg.configFile."mimeapps.list".text =
|
2020-02-01 23:39:17 +00:00
|
|
|
let joinValues = mapAttrs (n: concatStringsSep ";");
|
|
|
|
in generators.toINI { } {
|
|
|
|
"Added Associations" = joinValues cfg.associations.added;
|
|
|
|
"Removed Associations" = joinValues cfg.associations.removed;
|
|
|
|
"Default Applications" = joinValues cfg.defaultApplications;
|
|
|
|
};
|
2019-09-05 09:25:31 +00:00
|
|
|
};
|
|
|
|
}
|