From 34696c65a241a2a16bcb1c97946e179ead6e41ea Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Tue, 24 Jun 2025 21:24:05 +0200 Subject: [PATCH] libstore: fix race condition when creating state directories Running (parallel?) nix in nix can lead to multiple instances trying to create the state directories and failing on the createSymlink step, because the link already exists. `replaceSymlink` is already idempotent, so let's use that. See also: - https://github.com/NixOS/nix/pull/13368 - https://github.com/NixOS/nix/issues/2706 Change-Id: I7fadd0ce3c1ffcebc9d281c00e5b49c12af3d50b --- lix/libstore/local-store.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lix/libstore/local-store.cc b/lix/libstore/local-store.cc index 1d4ba8665..06fad5376 100644 --- a/lix/libstore/local-store.cc +++ b/lix/libstore/local-store.cc @@ -119,7 +119,7 @@ LocalStore::LocalStore(LocalStoreConfig config) Path gcRootsDir = config_.stateDir + "/gcroots"; if (!pathExists(gcRootsDir)) { createDirs(gcRootsDir); - createSymlink(profilesDir, gcRootsDir + "/profiles"); + replaceSymlink(profilesDir, gcRootsDir + "/profiles"); } for (auto & perUserDir : {profilesDir + "/per-user", gcRootsDir + "/per-user"}) {