1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

xdg-user-dirs: add createDirectories option

It automatically creates all the XDG user directories. Set to false as
default to not break backwards compatibility.
This commit is contained in:
Thiago Kenji Okada 2021-02-22 23:17:23 -03:00 committed by Robert Helgesson
parent ad04237d51
commit 6e3d93d7cc
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -86,11 +86,13 @@ in {
example = { XDG_MISC_DIR = "$HOME/Misc"; }; example = { XDG_MISC_DIR = "$HOME/Misc"; };
description = "Other user directories."; description = "Other user directories.";
}; };
createDirectories =
mkEnableOption "automatic creation of the XDG user directories";
}; };
config = mkIf cfg.enable { config = let
xdg.configFile."user-dirs.dirs".text = let directories = {
options = {
XDG_DESKTOP_DIR = cfg.desktop; XDG_DESKTOP_DIR = cfg.desktop;
XDG_DOCUMENTS_DIR = cfg.documents; XDG_DOCUMENTS_DIR = cfg.documents;
XDG_DOWNLOAD_DIR = cfg.download; XDG_DOWNLOAD_DIR = cfg.download;
@ -100,11 +102,20 @@ in {
XDG_TEMPLATES_DIR = cfg.templates; XDG_TEMPLATES_DIR = cfg.templates;
XDG_VIDEOS_DIR = cfg.videos; XDG_VIDEOS_DIR = cfg.videos;
} // cfg.extraConfig; } // cfg.extraConfig;
in mkIf cfg.enable {
xdg.configFile."user-dirs.dirs".text = let
# For some reason, these need to be wrapped with quotes to be valid. # For some reason, these need to be wrapped with quotes to be valid.
wrapped = mapAttrs (_: value: ''"${value}"'') options; wrapped = mapAttrs (_: value: ''"${value}"'') directories;
in generators.toKeyValue { } wrapped; in generators.toKeyValue { } wrapped;
xdg.configFile."user-dirs.conf".text = "enabled=False"; xdg.configFile."user-dirs.conf".text = "enabled=False";
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);
};
}; };
} }