|
36 | 36 | ''; |
37 | 37 | }; |
38 | 38 |
|
| 39 | + package = lib.mkPackageOption pkgs "xdg-user-dirs" { nullable = true; }; |
| 40 | + |
39 | 41 | # Well-known directory list from |
40 | 42 | # https://gitlab.freedesktop.org/xdg/xdg-user-dirs/blob/master/man/user-dirs.dirs.xml |
41 | 43 |
|
|
101 | 103 | defaultText = literalExpression "{ }"; |
102 | 104 | example = literalExpression '' |
103 | 105 | { |
104 | | - XDG_MISC_DIR = "''${config.home.homeDirectory}/Misc"; |
| 106 | + MISC = "''${config.home.homeDirectory}/Misc"; |
105 | 107 | } |
106 | 108 | ''; |
107 | | - description = "Other user directories."; |
| 109 | + description = '' |
| 110 | + Other user directories. |
| 111 | +
|
| 112 | + Prior to 25.11, these can be named like `XDG_MISC_DIR`. |
| 113 | + ''; |
108 | 114 | }; |
109 | 115 |
|
110 | 116 | createDirectories = lib.mkEnableOption "automatic creation of the XDG user directories"; |
| 117 | + |
| 118 | + setSessionVariables = mkOption { |
| 119 | + type = with types; bool; |
| 120 | + default = lib.versionOlder config.home.stateVersion "25.11"; |
| 121 | + defaultText = literalExpression '' |
| 122 | + lib.versionOlder config.home.stateVersion "25.11" |
| 123 | + ''; |
| 124 | + description = '' |
| 125 | + Whether to set the XDG user dir environment variables, like |
| 126 | + `XDG_DESKTOP_DIR`. The recommended way to get these values is via the |
| 127 | + `xdg-user-dir` command or by processing |
| 128 | + `$XDG_CONFIG_HOME/user-dirs.dirs` directly in your application. |
| 129 | +
|
| 130 | + This defaults to `true` for state version < 25.11 and `false` otherwise. |
| 131 | + ''; |
| 132 | + }; |
111 | 133 | }; |
112 | 134 |
|
113 | 135 | config = |
114 | 136 | let |
115 | 137 | directories = |
116 | 138 | (lib.filterAttrs (n: v: !isNull v) { |
117 | | - XDG_DESKTOP_DIR = cfg.desktop; |
118 | | - XDG_DOCUMENTS_DIR = cfg.documents; |
119 | | - XDG_DOWNLOAD_DIR = cfg.download; |
120 | | - XDG_MUSIC_DIR = cfg.music; |
121 | | - XDG_PICTURES_DIR = cfg.pictures; |
122 | | - XDG_PUBLICSHARE_DIR = cfg.publicShare; |
123 | | - XDG_TEMPLATES_DIR = cfg.templates; |
124 | | - XDG_VIDEOS_DIR = cfg.videos; |
| 139 | + DESKTOP = cfg.desktop; |
| 140 | + DOCUMENTS = cfg.documents; |
| 141 | + DOWNLOAD = cfg.download; |
| 142 | + MUSIC = cfg.music; |
| 143 | + PICTURES = cfg.pictures; |
| 144 | + PUBLICSHARE = cfg.publicShare; |
| 145 | + TEMPLATES = cfg.templates; |
| 146 | + VIDEOS = cfg.videos; |
125 | 147 | }) |
126 | | - // cfg.extraConfig; |
| 148 | + // ( |
| 149 | + if lib.versionOlder config.home.stateVersion "25.11" then |
| 150 | + lib.mapAttrs' ( |
| 151 | + k: |
| 152 | + let |
| 153 | + name = lib.match "XDG_(.*)_DIR" k; |
| 154 | + in |
| 155 | + lib.nameValuePair (if name == null then k else lib.elemAt name 0) |
| 156 | + ) cfg.extraConfig |
| 157 | + else |
| 158 | + cfg.extraConfig |
| 159 | + ); |
| 160 | + |
| 161 | + bindings = lib.mapAttrs' (k: lib.nameValuePair "XDG_${k}_DIR") directories; |
127 | 162 | in |
128 | 163 | lib.mkIf cfg.enable { |
129 | | - assertions = [ |
130 | | - (lib.hm.assertions.assertPlatform "xdg.userDirs" pkgs lib.platforms.linux) |
131 | | - ]; |
132 | | - |
133 | 164 | xdg.configFile."user-dirs.dirs".text = |
134 | 165 | let |
135 | 166 | # For some reason, these need to be wrapped with quotes to be valid. |
136 | | - wrapped = lib.mapAttrs (_: value: ''"${value}"'') directories; |
| 167 | + wrapped = lib.mapAttrs (_: value: ''"${value}"'') bindings; |
137 | 168 | in |
138 | 169 | lib.generators.toKeyValue { } wrapped; |
139 | 170 |
|
140 | 171 | xdg.configFile."user-dirs.conf".text = "enabled=False"; |
141 | 172 |
|
142 | | - home.sessionVariables = directories; |
| 173 | + home.packages = lib.mkIf (cfg.package != null) [ cfg.package ]; |
| 174 | + |
| 175 | + home.sessionVariables = lib.mkIf cfg.setSessionVariables bindings; |
143 | 176 |
|
144 | 177 | home.activation.createXdgUserDirectories = lib.mkIf cfg.createDirectories ( |
145 | 178 | let |
|
0 commit comments