1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-03-18 14:28:15 +00:00
home-manager/modules/misc/xdg-mime.nix
Austin Horstman 95711f9266
treewide: remove with lib (#6512)
* nixos: remove with lib
* nix-darwin: remove with lib
* home-manager: remove with lib
* modules/accounts: remove with lib
* modules/config: remove with lib
* modules/i18n: remove with lib
* modules/misc: remove with lib
* modules: remove with lib
* modules/targets: remove with lib
* tests/modules/firefox: remove with lib
* tests/modules/services: remove with lib
2025-03-07 14:16:46 -06:00

77 lines
2.4 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.xdg.mime;
inherit (lib) getExe getExe' mkOption types;
in {
options = {
xdg.mime = {
enable = mkOption {
type = types.bool;
default = pkgs.stdenv.hostPlatform.isLinux;
defaultText = lib.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 = lib.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 = lib.literalExpression "pkgs.desktop-file-utils";
description =
"The package to use when running update-desktop-database.";
};
};
};
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "xdg.mime" pkgs lib.platforms.linux)
];
home.packages = [
# Explicitly install package to provide basic mime types.
cfg.sharedMimeInfoPackage
# Make sure the target directories will be real directories.
(pkgs.runCommandLocal "dummy-xdg-mime-dirs1" { } ''
mkdir -p $out/share/{applications,mime/packages}
'')
(pkgs.runCommandLocal "dummy-xdg-mime-dirs2" { } ''
mkdir -p $out/share/{applications,mime/packages}
'')
];
home.extraProfileCommands = ''
if [[ -w $out/share/mime && -w $out/share/mime/packages && -d $out/share/mime/packages ]]; then
XDG_DATA_DIRS=$out/share \
PKGSYSTEM_ENABLE_FSYNC=0 \
${getExe cfg.sharedMimeInfoPackage} \
-V $out/share/mime > /dev/null
fi
if [[ -w $out/share/applications ]]; then
${getExe' cfg.desktopFileUtilsPackage "update-desktop-database"} \
$out/share/applications
fi
'';
};
}