From c5ae41d8be6eb391ae39de9cce58b5e6b9e8085b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 30 Apr 2024 16:39:34 +0200 Subject: [PATCH] Copy roots to the store as /nix/store/--source When you have a attribute like src = ./.; the root of the flake should produce a store path /nix/store/--source, because before lazy trees, the basename of the tree in the store was /nix/store/-source. Even though that was really a bug, we do need to mimic this behaviour so we don't change evaluation results. --- src/libexpr/eval.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 8e9e0c56083..ca61c33d438 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -2431,7 +2431,16 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat *store, path.resolveSymlinks(), settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy, - path.baseName(), + /* For backwards compatibility, if the path is the + root of a tree, we need to construct a + "double-copied" store path like + /nix/store/--source. We don't need to + materialize /nix/store/-source + though. Still, this requires reading/hashing the + path twice. */ + path.path.isRoot() + ? store->computeStorePath("source", *path.accessor, path.path).first.to_string() + : path.baseName(), FileIngestionMethod::Recursive, nullptr, repair);