2019-06-04 21:01:21 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "flakeref.hh"
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
class Store;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace nix::flake {
|
|
|
|
|
2019-08-30 17:27:51 +03:00
|
|
|
struct LockedInput;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
/* Lock file information about the dependencies of a flake. */
|
2019-08-30 17:27:51 +03:00
|
|
|
struct LockedInputs
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2019-08-30 17:27:51 +03:00
|
|
|
std::map<FlakeId, LockedInput> inputs;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-08-30 17:27:51 +03:00
|
|
|
LockedInputs() {};
|
|
|
|
LockedInputs(const nlohmann::json & json);
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
2019-07-12 14:29:54 +03:00
|
|
|
|
|
|
|
/* A lock file is dirty if it contains a dirty flakeref
|
|
|
|
(i.e. reference to a dirty working tree). */
|
|
|
|
bool isDirty() const;
|
2019-06-04 21:01:21 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Lock file information about a flake input. */
|
2019-08-30 17:27:51 +03:00
|
|
|
struct LockedInput : LockedInputs
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2019-09-18 22:17:27 +03:00
|
|
|
FlakeRef ref, originalRef;
|
2019-08-30 17:27:51 +03:00
|
|
|
Hash narHash;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-09-18 22:17:27 +03:00
|
|
|
LockedInput(const FlakeRef & ref, const FlakeRef & originalRef, const Hash & narHash)
|
|
|
|
: ref(ref), originalRef(originalRef), narHash(narHash)
|
2019-08-30 17:27:51 +03:00
|
|
|
{
|
|
|
|
assert(ref.isImmutable());
|
|
|
|
};
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-08-30 17:27:51 +03:00
|
|
|
LockedInput(const nlohmann::json & json);
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-08-30 17:27:51 +03:00
|
|
|
bool operator ==(const LockedInput & other) const
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
|
|
|
return
|
2019-08-30 17:27:51 +03:00
|
|
|
ref == other.ref
|
2019-06-04 21:01:21 +03:00
|
|
|
&& narHash == other.narHash
|
2019-08-30 17:27:51 +03:00
|
|
|
&& inputs == other.inputs;
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
2019-08-30 17:27:51 +03:00
|
|
|
|
|
|
|
Path computeStorePath(Store & store) const;
|
2019-06-04 21:01:21 +03:00
|
|
|
};
|
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
/* An entire lock file. Note that this cannot be a FlakeInput for the
|
2019-06-04 21:01:21 +03:00
|
|
|
top-level flake, because then the lock file would need to contain
|
|
|
|
the hash of the top-level flake, but committing the lock file
|
|
|
|
would invalidate that hash. */
|
2019-08-30 17:27:51 +03:00
|
|
|
struct LockFile : LockedInputs
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
|
|
|
bool operator ==(const LockFile & other) const
|
|
|
|
{
|
2019-08-30 17:27:51 +03:00
|
|
|
return inputs == other.inputs;
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LockFile() {}
|
2019-08-30 17:27:51 +03:00
|
|
|
LockFile(const nlohmann::json & json) : LockedInputs(json) {}
|
|
|
|
LockFile(LockedInput && dep)
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2019-08-30 17:27:51 +03:00
|
|
|
inputs = std::move(dep.inputs);
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
|
|
|
|
|
|
|
static LockFile read(const Path & path);
|
|
|
|
|
|
|
|
void write(const Path & path) const;
|
|
|
|
};
|
|
|
|
|
2019-06-04 21:34:44 +03:00
|
|
|
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile);
|
|
|
|
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|
|
|
|
|