fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
1.8 KiB60 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.xdg.mime;
8
9in {
10  options = {
11    xdg.mime.enable = mkOption {
12      type = types.bool;
13      default = pkgs.stdenv.hostPlatform.isLinux;
14      defaultText =
15        literalExpression "true if host platform is Linux, false otherwise";
16      description = ''
17        Whether to install programs and files to support the
18        XDG Shared MIME-info specification and XDG MIME Applications
19        specification at
20        <https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html>
21        and
22        <https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html>,
23        respectively.
24      '';
25    };
26  };
27
28  config = mkIf config.xdg.mime.enable {
29    assertions =
30      [ (hm.assertions.assertPlatform "xdg.mime" pkgs platforms.linux) ];
31
32    home.packages = [
33      # Explicitly install package to provide basic mime types.
34      pkgs.shared-mime-info
35
36      # Make sure the target directories will be real directories.
37      (pkgs.runCommandLocal "dummy-xdg-mime-dirs1" { } ''
38        mkdir -p $out/share/{applications,mime/packages}
39      '')
40      (pkgs.runCommandLocal "dummy-xdg-mime-dirs2" { } ''
41        mkdir -p $out/share/{applications,mime/packages}
42      '')
43    ];
44
45    home.extraProfileCommands = ''
46      if [[ -w $out/share/mime && -w $out/share/mime/packages && -d $out/share/mime/packages ]]; then
47        XDG_DATA_DIRS=$out/share \
48        PKGSYSTEM_ENABLE_FSYNC=0 \
49        ${pkgs.buildPackages.shared-mime-info}/bin/update-mime-database \
50          -V $out/share/mime > /dev/null
51      fi
52
53      if [[ -w $out/share/applications ]]; then
54        ${pkgs.buildPackages.desktop-file-utils}/bin/update-desktop-database \
55          $out/share/applications
56      fi
57    '';
58  };
59
60}