diff --git a/lib/path/default.nix b/lib/path/default.nix index be559eadf182..1284bed94bb0 100644 --- a/lib/path/default.nix +++ b/lib/path/default.nix @@ -165,7 +165,7 @@ let # This is a workaround for https://github.com/NixOS/nix/issues/12361 which # was needed during the experimental phase of ca-derivations and should be # removed once the issue has been resolved. - || match "[0-9a-z]{52}" (head components) != null; + || components != [ ] && match "[0-9a-z]{52}" (head components) != null; in # No rec! Add dependencies on this file at the top. diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix index a52b4f44e51d..fa2e004e9c3a 100644 --- a/lib/path/tests/unit.nix +++ b/lib/path/tests/unit.nix @@ -110,6 +110,12 @@ let expected = false; }; + # Root path (empty path components list) + testHasStorePathPrefixRoot = { + expr = hasStorePathPrefix /.; + expected = false; + }; + testHasStorePathPrefixExample1 = { expr = hasStorePathPrefix (storeDirPath + "/nvl9ic0pj1fpyln3zaqrf4cclbqdfn1j-foo/bar/baz"); expected = true;