mirror of
https://github.com/NixOS/nix
synced 2025-06-25 19:01:16 +02:00
Only rewrite the lockfile if it changed
This removes spurious warnings about failure to write the lockfile.
This commit is contained in:
parent
818c8da5b8
commit
20a1a65d37
2 changed files with 37 additions and 12 deletions
|
@ -465,31 +465,35 @@ ResolvedFlake resolveFlakeFromLockFile(EvalState & state, const FlakeRef & flake
|
|||
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, HandleLockFile handleLockFile)
|
||||
{
|
||||
Flake flake = getFlake(state, topRef, allowedToUseRegistries(handleLockFile, true));
|
||||
LockFile lockFile;
|
||||
LockFile oldLockFile;
|
||||
|
||||
if (!recreateLockFile (handleLockFile)) {
|
||||
// If recreateLockFile, start with an empty lockfile
|
||||
lockFile = readLockFile(flake.storePath + "/flake.lock"); // FIXME: symlink attack
|
||||
oldLockFile = readLockFile(flake.storePath + "/flake.lock"); // FIXME: symlink attack
|
||||
}
|
||||
|
||||
LockFile lockFile(oldLockFile);
|
||||
|
||||
ResolvedFlake resFlake = resolveFlakeFromLockFile(state, topRef, handleLockFile, lockFile, true);
|
||||
lockFile = entryToLockFile(dependenciesToFlakeEntry(resFlake));
|
||||
|
||||
if (allowedToWrite(handleLockFile)) {
|
||||
if (auto refData = std::get_if<FlakeRef::IsPath>(&topRef.data)) {
|
||||
writeLockFile(lockFile, refData->path + (topRef.subdir == "" ? "" : "/" + topRef.subdir) + "/flake.lock");
|
||||
if (!(lockFile == oldLockFile)) {
|
||||
if (allowedToWrite(handleLockFile)) {
|
||||
if (auto refData = std::get_if<FlakeRef::IsPath>(&topRef.data)) {
|
||||
writeLockFile(lockFile, refData->path + (topRef.subdir == "" ? "" : "/" + topRef.subdir) + "/flake.lock");
|
||||
|
||||
// Hack: Make sure that flake.lock is visible to Git, so it ends up in the Nix store.
|
||||
runProgram("git", true, { "-C", refData->path, "add",
|
||||
(topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock" });
|
||||
} else std::cout << "Cannot write lockfile because the FlakeRef isn't of the form IsPath." << std::endl;
|
||||
} else if (handleLockFile != AllPure && handleLockFile != TopRefUsesRegistries)
|
||||
std::cout << "Using updating lockfile without writing it to file" << std::endl;
|
||||
// Hack: Make sure that flake.lock is visible to Git, so it ends up in the Nix store.
|
||||
runProgram("git", true, { "-C", refData->path, "add",
|
||||
(topRef.subdir == "" ? "" : topRef.subdir + "/") + "flake.lock" });
|
||||
} else std::cout << "Cannot write lockfile because the FlakeRef isn't of the form IsPath." << std::endl;
|
||||
} else if (handleLockFile != AllPure && handleLockFile != TopRefUsesRegistries)
|
||||
std::cout << "Using updating lockfile without writing it to file" << std::endl;
|
||||
}
|
||||
|
||||
return resFlake;
|
||||
}
|
||||
|
||||
void updateLockFile (EvalState & state, const FlakeUri & flakeUri, bool recreateLockFile)
|
||||
void updateLockFile(EvalState & state, const FlakeUri & flakeUri, bool recreateLockFile)
|
||||
{
|
||||
FlakeRef flakeRef(flakeUri);
|
||||
resolveFlake(state, flakeRef, recreateLockFile ? RecreateLockFile : UpdateLockFile);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue