about summary refs log tree commit diff
path: root/modules/common/xdg.nix
blob: df7d624b4b6997f3f31f98c2f890d91aaab11af0 (plain) (blame)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
  config,
  lib,
  this,
  ...
}:
let
  cfg = config.nixfiles.modules.common.xdg;
in
{
  imports =
    let
      withBase = a: [
        "nixfiles"
        "modules"
        "common"
        "xdg"
        a
      ];
    in
    [
      (lib.mkAliasOptionModule [
        "dirs"
        "cache"
      ] (withBase "cacheHome"))
      (lib.mkAliasOptionModule [
        "dirs"
        "config"
      ] (withBase "configHome"))
      (lib.mkAliasOptionModule [
        "dirs"
        "data"
      ] (withBase "dataHome"))
      (lib.mkAliasOptionModule [
        "dirs"
        "state"
      ] (withBase "stateHome"))
      (lib.mkAliasOptionModule [ "userDirs" ] (withBase "userDirs"))
    ];

  options.nixfiles.modules.common.xdg = {
    cacheHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.cache";
    };
    configHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.config";
    };
    dataHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.local/share";
    };
    stateHome = lib.mkOption {
      type = lib.types.str;
      default = "${config.hm.home.homeDirectory}/.local/state";
    };
    userDirs = lib.mkOption {
      type = lib.types.attrs;
      default =
        let
          inherit (config.my) home;
          tmp = home + "/tmp";
        in
        {
          enable = true;

          desktop = tmp;
          documents = "${home}/doc";
          download = tmp;
          music = tmp;
          pictures = tmp;
          publicShare = "${home}/share";
          templates = tmp;
          videos = tmp;
        };
    };
    defaultApplications = lib.mkOption {
      description = "Default applications.";
      type = with lib.types; attrsOf (listOf str);
      default = { };
    };
  };

  config = {
    xdg = {
      portal.enable = this.isHeadful;
      sounds.enable = this.isHeadful;
    };

    hm.xdg = lib.mkMerge [
      (with cfg; {
        enable = true;

        inherit cacheHome;
        inherit configHome;
        inherit dataHome;
        inherit stateHome;
        inherit userDirs;
      })
      (lib.mkIf this.isHeadful {
        mimeApps = {
          enable = true;
          defaultApplications = lib.mkMerge (
            lib.mapAttrsToList (n: v: lib.genAttrs v (_: [ "${n}.desktop" ])) cfg.defaultApplications
          );
        };
      })
    ];
  };
}

Consider giving Nix/NixOS a try! <3