1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 19:46:05 +01:00
home-manager/modules/misc/xdg-mime.nix
Austin Horstman 7419250703
treewide: convert package options to use mkPackageOption (#7116)
This commit converts `package = mkOption` declarations throughout the
codebase to use the more modern and consistent `lib.mkPackageOption`
function.

Key changes:
- Simple package options: `mkOption { type = types.package; default = pkgs.foo; }`
  becomes `lib.mkPackageOption pkgs "foo" { }`
- Package set options: Uses correct package set as first argument with
  `pkgsText` parameter (e.g., `lib.mkPackageOption pkgs.vimPlugins "plugin" { pkgsText = "pkgs.vimPlugins"; }`)
- Removes redundant descriptions that just restate the package name
- Preserves examples and extra context where meaningful
- Handles submodule plugin options properly with `null` defaults

This modernizes the option declarations and makes them more consistent
with current nixpkgs patterns while maintaining full backward compatibility.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-05-23 00:42:38 -05:00

82 lines
2.3 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 = lib.mkPackageOption pkgs "shared-mime-info" {
extraDescription = "Used when running update-mime-database.";
};
desktopFileUtilsPackage = lib.mkPackageOption pkgs "desktop-file-utils" {
extraDescription = "Used 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.__spliced.buildHost or cfg.sharedMimeInfoPackage)
} -V $out/share/mime > /dev/null
fi
if [[ -w $out/share/applications ]]; then
${
getExe' (cfg.desktopFileUtilsPackage.__spliced.buildHost or cfg.desktopFileUtilsPackage
) "update-desktop-database"
} $out/share/applications
fi
'';
};
}