2019-11-10 21:36:16 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xdg.mime;
|
2024-10-07 23:39:24 +02:00
|
|
|
inherit (lib) getExe getExe';
|
2019-11-10 21:36:16 +01:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2019-11-10 21:36:16 +01:00
|
|
|
options = {
|
2024-10-07 23:39:24 +02:00
|
|
|
xdg.mime = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = pkgs.stdenv.hostPlatform.isLinux;
|
|
|
|
defaultText =
|
|
|
|
literalExpression "true if host platform is Linux, false otherwise";
|
|
|
|
description = ''
|
|
|
|
Whether to install programs and files to support the
|
|
|
|
XDG Shared MIME-info specification and XDG MIME Applications
|
|
|
|
specification at
|
|
|
|
<https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html>
|
|
|
|
and
|
|
|
|
<https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html>,
|
|
|
|
respectively.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
sharedMimeInfoPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.shared-mime-info;
|
|
|
|
defaultText = literalExpression "pkgs.shared-mime-info";
|
|
|
|
description = "The package to use when running update-mime-database.";
|
|
|
|
};
|
|
|
|
|
|
|
|
desktopFileUtilsPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.desktop-file-utils;
|
|
|
|
defaultText = literalExpression "pkgs.desktop-file-utils";
|
|
|
|
description =
|
|
|
|
"The package to use when running update-desktop-database.";
|
|
|
|
};
|
2019-11-10 21:36:16 +01:00
|
|
|
};
|
|
|
|
};
|
2024-10-07 23:39:24 +02:00
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions =
|
|
|
|
[ (hm.assertions.assertPlatform "xdg.mime" pkgs platforms.linux) ];
|
|
|
|
|
2019-11-10 21:36:16 +01:00
|
|
|
home.packages = [
|
|
|
|
# Explicitly install package to provide basic mime types.
|
2024-10-07 23:39:24 +02:00
|
|
|
cfg.sharedMimeInfoPackage
|
2020-08-15 00:17:24 +02:00
|
|
|
|
|
|
|
# Make sure the target directories will be real directories.
|
2020-08-29 17:33:07 +02:00
|
|
|
(pkgs.runCommandLocal "dummy-xdg-mime-dirs1" { } ''
|
|
|
|
mkdir -p $out/share/{applications,mime/packages}
|
|
|
|
'')
|
|
|
|
(pkgs.runCommandLocal "dummy-xdg-mime-dirs2" { } ''
|
2020-08-15 00:17:24 +02:00
|
|
|
mkdir -p $out/share/{applications,mime/packages}
|
|
|
|
'')
|
2019-11-10 21:36:16 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
home.extraProfileCommands = ''
|
2020-06-04 19:45:22 +02:00
|
|
|
if [[ -w $out/share/mime && -w $out/share/mime/packages && -d $out/share/mime/packages ]]; then
|
2019-11-10 21:36:16 +01:00
|
|
|
XDG_DATA_DIRS=$out/share \
|
|
|
|
PKGSYSTEM_ENABLE_FSYNC=0 \
|
2024-10-07 23:39:24 +02:00
|
|
|
${getExe cfg.sharedMimeInfoPackage} \
|
2019-11-10 21:36:16 +01:00
|
|
|
-V $out/share/mime > /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -w $out/share/applications ]]; then
|
2024-10-07 23:39:24 +02:00
|
|
|
${getExe' cfg.desktopFileUtilsPackage "update-desktop-database"} \
|
2019-11-10 21:36:16 +01:00
|
|
|
$out/share/applications
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|