about summary refs log tree commit diff
path: root/modules/xdg/default.nix
blob: b24b18f4db08fe22e1fd63aee7b014e56e5c0e4a (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
{ lib, pkgs, config, ... }:

let
  inherit (lib) filterAttrs mapAttrsToList mkOption;
  inherit (lib.types) loaOf attrsOf path submodule;
  inherit (pkgs) linkFarm;

  userOptions = {
    options.xdg.config.paths = mkOption {
      default = {};
      type = attrsOf path;
    };
  };

in
  {
    options = {
      users.users = mkOption {
        type = loaOf (submodule userOptions);
      };
    };

    config = {
      environment.etc."xdg/nixos/per-user".source =
        linkFarm "xdg-config-users"
                  (mapAttrsToList (user: { xdg, ... }: {
                    name = user;
                    path = linkFarm "${user}-xdg-config-home"
                                    (mapAttrsToList
                                      (name: path: { inherit name path; })
                                      xdg.config.paths);
                  }) (filterAttrs (_: { xdg, ... }: xdg.config.paths != {})
                                  config.users.users));

      environment.sessionVariables = {
        XDG_CONFIG_HOME = "/run/current-system/etc/xdg/nixos/per-user/$USER";
        XDG_DATA_HOME = "$HOME/state";
        XDG_CACHE_HOME = "$HOME/state/cache";
        XDG_STATE_HOME = "$HOME/state";
      };
    };
  }