xdg-user-dirs: check for existing symlink

When a non-directory, such as a file or a dead symlink, already exists,
mkdir -p fails with "cannot create directory ‘...’: File exists".

This is a problem when, for example, a symlink points to a directory on
a filesystem that isn't mounted yet.
This commit is contained in:
novenary 2024-03-07 12:16:58 +02:00
parent cf111d1a84
commit 1283bf6ebb

View file

@ -137,7 +137,8 @@ in {
home.activation.createXdgUserDirectories = mkIf cfg.createDirectories (let
directoriesList = attrValues directories;
mkdir = (dir: ''run mkdir -p $VERBOSE_ARG "${dir}"'');
mkdir =
(dir: ''[[ -L "${dir}" ]] || run mkdir -p $VERBOSE_ARG "${dir}"'');
in lib.hm.dag.entryAfter [ "linkGeneration" ]
(strings.concatMapStringsSep "\n" mkdir directoriesList));
};