From 571989f564311475d26200cd303941c68e8488a7 Mon Sep 17 00:00:00 2001 From: Sebastian Ullrich Date: Sun, 10 Nov 2019 21:36:16 +0100 Subject: [PATCH] xdg-mime: add module --- modules/misc/news.nix | 12 ++++++++++ modules/misc/xdg-mime.nix | 49 +++++++++++++++++++++++++++++++++++++++ modules/modules.nix | 1 + 3 files changed, 62 insertions(+) create mode 100644 modules/misc/xdg-mime.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f1074fc16..80aeb47c9 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1268,6 +1268,18 @@ in A new module is available: 'services.unison'. ''; } + + { + time = "2019-12-01T22:10:23+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'xdg.mime'. + + If enabled, which it is by default, this module will create + the XDG mime database and desktop file database caches from + programs installed via Home Manager. + ''; + } ]; }; } diff --git a/modules/misc/xdg-mime.nix b/modules/misc/xdg-mime.nix new file mode 100644 index 000000000..0063e43d2 --- /dev/null +++ b/modules/misc/xdg-mime.nix @@ -0,0 +1,49 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.xdg.mime; + +in + +{ + options = { + xdg.mime.enable = mkOption { + type = types.bool; + default = true; + description = '' + Whether to install programs and files to support the + XDG Shared MIME-info specification and XDG MIME Applications + specification at + + and + , + respectively. + ''; + }; + }; + + config = mkIf config.xdg.mime.enable { + home.packages = [ + # Explicitly install package to provide basic mime types. + pkgs.shared-mime-info + ]; + + home.extraProfileCommands = '' + if [[ -w $out/share/mime && -d $out/share/mime/packages ]]; then + 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 + ''; + }; + +} diff --git a/modules/modules.nix b/modules/modules.nix index f32a9d7c0..99543de0f 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -33,6 +33,7 @@ let (loadModule ./misc/qt.nix { }) (loadModule ./misc/submodule-support.nix { }) (loadModule ./misc/version.nix { }) + (loadModule ./misc/xdg-mime.nix { condition = hostPlatform.isLinux; }) (loadModule ./misc/xdg-mime-apps.nix { condition = hostPlatform.isLinux; }) (loadModule ./misc/xdg-user-dirs.nix { condition = hostPlatform.isLinux; }) (loadModule ./misc/xdg.nix { })