2019-09-05 11:18:43 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xdg.userDirs;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2019-09-05 11:18:43 +02:00
|
|
|
meta.maintainers = with maintainers; [ pacien ];
|
|
|
|
|
2020-01-13 10:48:07 +01:00
|
|
|
imports = [
|
2020-02-02 00:39:17 +01:00
|
|
|
(mkRenamedOptionModule [ "xdg" "userDirs" "publishShare" ] [
|
|
|
|
"xdg"
|
|
|
|
"userDirs"
|
|
|
|
"publicShare"
|
|
|
|
])
|
2020-01-13 10:48:07 +01:00
|
|
|
];
|
|
|
|
|
2019-09-05 11:18:43 +02:00
|
|
|
options.xdg.userDirs = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to manage <filename>$XDG_CONFIG_HOME/user-dirs.dirs</filename>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The generated file is read-only.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# Well-known directory list from
|
|
|
|
# https://gitlab.freedesktop.org/xdg/xdg-user-dirs/blob/master/man/user-dirs.dirs.xml
|
|
|
|
|
|
|
|
desktop = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Desktop";
|
|
|
|
description = "The Desktop directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
documents = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Documents";
|
|
|
|
description = "The Documents directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
download = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Downloads";
|
|
|
|
description = "The Downloads directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
music = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Music";
|
|
|
|
description = "The Music directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
pictures = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Pictures";
|
|
|
|
description = "The Pictures directory.";
|
|
|
|
};
|
|
|
|
|
2020-01-13 10:48:07 +01:00
|
|
|
publicShare = mkOption {
|
2019-09-05 11:18:43 +02:00
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Public";
|
|
|
|
description = "The Public share directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
templates = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Templates";
|
|
|
|
description = "The Templates directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
videos = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/Videos";
|
|
|
|
description = "The Videos directory.";
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = with types; attrsOf str;
|
|
|
|
default = { };
|
|
|
|
example = { XDG_MISC_DIR = "$HOME/Misc"; };
|
|
|
|
description = "Other user directories.";
|
|
|
|
};
|
2021-02-23 03:17:23 +01:00
|
|
|
|
|
|
|
createDirectories =
|
|
|
|
mkEnableOption "automatic creation of the XDG user directories";
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
|
2021-02-23 03:17:23 +01:00
|
|
|
config = let
|
|
|
|
directories = {
|
|
|
|
XDG_DESKTOP_DIR = cfg.desktop;
|
|
|
|
XDG_DOCUMENTS_DIR = cfg.documents;
|
|
|
|
XDG_DOWNLOAD_DIR = cfg.download;
|
|
|
|
XDG_MUSIC_DIR = cfg.music;
|
|
|
|
XDG_PICTURES_DIR = cfg.pictures;
|
|
|
|
XDG_PUBLICSHARE_DIR = cfg.publicShare;
|
|
|
|
XDG_TEMPLATES_DIR = cfg.templates;
|
|
|
|
XDG_VIDEOS_DIR = cfg.videos;
|
|
|
|
} // cfg.extraConfig;
|
|
|
|
in mkIf cfg.enable {
|
2020-08-12 22:51:20 +02:00
|
|
|
xdg.configFile."user-dirs.dirs".text = let
|
|
|
|
# For some reason, these need to be wrapped with quotes to be valid.
|
2021-02-23 03:17:23 +01:00
|
|
|
wrapped = mapAttrs (_: value: ''"${value}"'') directories;
|
2020-08-12 22:51:20 +02:00
|
|
|
in generators.toKeyValue { } wrapped;
|
2020-04-12 20:39:52 +02:00
|
|
|
|
|
|
|
xdg.configFile."user-dirs.conf".text = "enabled=False";
|
2021-02-23 03:17:23 +01:00
|
|
|
|
|
|
|
home.activation = mkIf cfg.createDirectories {
|
|
|
|
createXdgUserDirectories = let
|
|
|
|
directoriesList = attrValues directories;
|
|
|
|
mkdir = (dir: ''$DRY_RUN_CMD mkdir -p $VERBOSE_ARG "${dir}"'');
|
|
|
|
in lib.hm.dag.entryAfter [ "writeBoundary" ]
|
|
|
|
(strings.concatMapStringsSep "\n" mkdir directoriesList);
|
|
|
|
};
|
2019-09-05 11:18:43 +02:00
|
|
|
};
|
|
|
|
}
|