summaryrefslogtreecommitdiff
path: root/modules/nixfiles/common/xdg.nix
blob: c05f5e3c841b0125b3993e3636e70b0f331f8682 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{
  config,
  lib,
  this,
  ...
}:
with lib; {
  imports = let
    withBase = s: ["home-manager" "users" my.username "xdg" s];
  in [
    (mkAliasOptionModule ["dirs" "cache"] (withBase "cacheHome"))
    (mkAliasOptionModule ["dirs" "config"] (withBase "configHome"))
    (mkAliasOptionModule ["dirs" "data"] (withBase "dataHome"))
    (mkAliasOptionModule ["dirs" "state"] (withBase "stateHome"))
    (mkAliasOptionModule ["userDirs"] (withBase "userDirs"))
  ];

  hm = {
    xdg = mkMerge [
      {
        enable = true;

        userDirs = let
          inherit (config.my) home;
          tmp = home + "/tmp";
        in {
          enable = true;

          createDirectories = this.isHeadful;

          desktop = tmp;
          documents = "${home}/doc";
          download = tmp;
          music = tmp;
          pictures = tmp;
          videos = tmp;
          templates = tmp;
          publicShare = "${home}/share";
        };
      }
      (mkIf this.isHeadful {
        mimeApps = let
          images = [
            "image/bmp"
            "image/gif"
            "image/jpeg"
            "image/jpg"
            "image/png"
            "image/svg+xml"
            "image/tiff"
            "image/webp"
          ];
          media = [
            "audio/aac"
            "audio/flac"
            "audio/mp3"
            "audio/ogg"
            "audio/wav"
            "audio/webm"
            "video/mkv"
            "video/mp4"
            "video/ogg"
            "video/webm"
            "video/x-matroska"
          ];
        in {
          enable = true;

          defaultApplications =
            mkMerge
            (mapAttrsToList (n: ms: genAttrs ms (_: ["${n}.desktop"])) {
              aria2 = ["application/x-bittorrent" "x-scheme-handler/magnet"];
              emacsclient = ["x-scheme-handler/mailto"];
              firefox = [
                "text/html"
                "x-scheme-handler/http"
                "x-scheme-handler/https"
              ];
              gwenview = images;
              mpv = media;
            });
        };
      })
    ];
  };
}