2019-06-04 21:01:21 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "flakeref.hh"
|
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
class Store;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace nix::flake {
|
|
|
|
|
|
|
|
/* Common lock file information about a flake input, namely the
|
|
|
|
immutable ref and the NAR hash. */
|
2019-06-04 21:08:13 +03:00
|
|
|
struct AbstractInput
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
|
|
|
FlakeRef ref;
|
|
|
|
Hash narHash;
|
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
AbstractInput(const FlakeRef & flakeRef, const Hash & narHash)
|
2019-06-04 21:01:21 +03:00
|
|
|
: ref(flakeRef), narHash(narHash)
|
|
|
|
{
|
|
|
|
assert(ref.isImmutable());
|
|
|
|
};
|
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
AbstractInput(const nlohmann::json & json);
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
|
|
|
|
|
|
|
Path computeStorePath(Store & store) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Lock file information about a non-flake input. */
|
2019-06-04 21:08:13 +03:00
|
|
|
struct NonFlakeInput : AbstractInput
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2019-06-04 21:08:13 +03:00
|
|
|
using AbstractInput::AbstractInput;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
bool operator ==(const NonFlakeInput & other) const
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
|
|
|
return ref == other.ref && narHash == other.narHash;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
struct FlakeInput;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
/* Lock file information about the dependencies of a flake. */
|
|
|
|
struct FlakeInputs
|
|
|
|
{
|
2019-06-04 21:08:13 +03:00
|
|
|
std::map<FlakeRef, FlakeInput> flakeInputs;
|
|
|
|
std::map<FlakeAlias, NonFlakeInput> nonFlakeInputs;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
FlakeInputs() {};
|
|
|
|
FlakeInputs(const nlohmann::json & json);
|
|
|
|
|
|
|
|
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-06-04 21:08:13 +03:00
|
|
|
struct FlakeInput : FlakeInputs, AbstractInput
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
|
|
|
FlakeId id;
|
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
FlakeInput(const FlakeId & id, const FlakeRef & flakeRef, const Hash & narHash)
|
|
|
|
: AbstractInput(flakeRef, narHash), id(id) {};
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
FlakeInput(const nlohmann::json & json);
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2019-06-04 21:08:13 +03:00
|
|
|
bool operator ==(const FlakeInput & other) const
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
|
|
|
return
|
|
|
|
id == other.id
|
|
|
|
&& ref == other.ref
|
|
|
|
&& narHash == other.narHash
|
2019-06-04 21:08:13 +03:00
|
|
|
&& flakeInputs == other.flakeInputs
|
|
|
|
&& nonFlakeInputs == other.nonFlakeInputs;
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
|
|
|
};
|
|
|
|
|
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. */
|
|
|
|
struct LockFile : FlakeInputs
|
|
|
|
{
|
|
|
|
bool operator ==(const LockFile & other) const
|
|
|
|
{
|
|
|
|
return
|
2019-06-04 21:08:13 +03:00
|
|
|
flakeInputs == other.flakeInputs
|
|
|
|
&& nonFlakeInputs == other.nonFlakeInputs;
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LockFile() {}
|
|
|
|
LockFile(const nlohmann::json & json) : FlakeInputs(json) {}
|
2019-06-04 21:08:13 +03:00
|
|
|
LockFile(FlakeInput && dep)
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2019-06-04 21:08:13 +03:00
|
|
|
flakeInputs = std::move(dep.flakeInputs);
|
|
|
|
nonFlakeInputs = std::move(dep.nonFlakeInputs);
|
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
|
|
|
}
|
|
|
|
|