flake.lock now uses flakeRef.subdir

This commit is contained in:
Nick Van den Broeck 2019-05-01 16:24:33 +02:00
parent 00db8d4549
commit 43408d3cd6
2 changed files with 13 additions and 10 deletions

View file

@ -285,7 +285,7 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef, bool impureIsAllowe
+ "/" + flake.sourceInfo.rev->to_string(Base16, false));
}
Path flakeFile = sourceInfo.storePath + resolvedRef.subdir + "/flake.nix";
Path flakeFile = sourceInfo.storePath + "/" + resolvedRef.subdir + "/flake.nix";
if (!pathExists(flakeFile))
throw Error("source tree referenced by '%s' does not contain a 'flake.nix' file", resolvedRef);
@ -367,7 +367,7 @@ ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef,
LockFile lockFile;
if (isTopFlake)
lockFile = readLockFile(flake.sourceInfo.storePath + "/flake.lock"); // FIXME: symlink attack
lockFile = readLockFile(flake.sourceInfo.storePath + "/" + flake.resolvedRef.subdir + "/flake.lock"); // FIXME: symlink attack
ResolvedFlake deps(flake);
@ -407,16 +407,19 @@ static LockFile makeLockFile(EvalState & evalState, FlakeRef & flakeRef)
return lockFile;
}
void updateLockFile(EvalState & state, const Path & path)
void updateLockFile(EvalState & state, const FlakeUri & flakeUri)
{
// FIXME: We are writing the lockfile to the store here! Very bad practice!
FlakeRef flakeRef = FlakeRef(path);
FlakeRef flakeRef = FlakeRef(flakeUri);
if (auto refData = std::get_if<IsPath>(flakeRef)) {
auto lockFile = makeLockFile(state, flakeRef);
writeLockFile(lockFile, path + "/flake.lock");
writeLockFile(lockFile, refData->path + "/" + flakeRef.subdir + "/flake.lock");
// Hack: Make sure that flake.lock is visible to Git. Otherwise,
// exportGit will fail to copy it to the Nix store.
runProgram("git", true, { "-C", path, "add", "flake.lock" });
runProgram("git", true, { "-C", refData->path, "add", flakeRef.subDir + "/flake.lock" });
} else
throw Error("flakeUri %s can't be updated because it is not a path", flakeUri);
}
void callFlake(EvalState & state, const ResolvedFlake & resFlake, Value & v)

View file

@ -90,7 +90,7 @@ struct ResolvedFlake
ResolvedFlake resolveFlake(EvalState &, const FlakeRef &, RegistryAccess registryAccess, bool isTopFlake = true);
void updateLockFile(EvalState &, const Path & path);
void updateLockFile(EvalState &, const FlakeUri &);
void gitCloneFlake (std::string flakeUri, EvalState &, Registries, Path);
}