2019-11-10 21:36:16 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xdg.mime;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2019-11-10 21:36:16 +01:00
|
|
|
options = {
|
|
|
|
xdg.mime.enable = mkOption {
|
|
|
|
type = types.bool;
|
2021-12-03 06:30:34 +01:00
|
|
|
default = pkgs.stdenv.hostPlatform.isLinux;
|
2021-07-07 23:24:27 +02:00
|
|
|
defaultText =
|
2021-10-09 11:14:08 +02:00
|
|
|
literalExpression "true if host platform is Linux, false otherwise";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-11-10 21:36:16 +01:00
|
|
|
Whether to install programs and files to support the
|
|
|
|
XDG Shared MIME-info specification and XDG MIME Applications
|
|
|
|
specification at
|
2023-07-01 01:30:13 +02:00
|
|
|
<https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html>
|
2019-11-10 21:36:16 +01:00
|
|
|
and
|
2023-07-01 01:30:13 +02:00
|
|
|
<https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html>,
|
2019-11-10 21:36:16 +01:00
|
|
|
respectively.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.xdg.mime.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.
|
|
|
|
pkgs.shared-mime-info
|
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 \
|
|
|
|
${pkgs.buildPackages.shared-mime-info}/bin/update-mime-database \
|
|
|
|
-V $out/share/mime > /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -w $out/share/applications ]]; then
|
|
|
|
${pkgs.buildPackages.desktop-file-utils}/bin/update-desktop-database \
|
|
|
|
$out/share/applications
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|