From 1283bf6ebbdee4d980b7551bed4c6596805e812c Mon Sep 17 00:00:00 2001 From: novenary Date: Thu, 7 Mar 2024 12:16:58 +0200 Subject: [PATCH] xdg-user-dirs: check for existing symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- modules/misc/xdg-user-dirs.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/misc/xdg-user-dirs.nix b/modules/misc/xdg-user-dirs.nix index c9912812f..1198ea039 100644 --- a/modules/misc/xdg-user-dirs.nix +++ b/modules/misc/xdg-user-dirs.nix @@ -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)); };