mirror of
https://github.com/NixOS/nix.git
synced 2025-12-23 01:11:07 +01:00
* Finish converting existing comments for internal API docs 99% of this was just reformatting existing comments. Only two exceptions: - Expanded upon `BuildResult::status` compat note - Split up file-level `symbol-table.hh` doc comments to get per-definition docs Also fixed a few whitespace goofs, turning leading tabs to spaces and removing trailing spaces. Picking up from #8133 * Fix two things from comments * Use triple-backtick not indent for `dumpPath` * Convert GNU-style `\`..'` quotes to markdown style in API docs This will render correctly.
95 lines
2 KiB
C++
95 lines
2 KiB
C++
#pragma once
|
|
///@file
|
|
|
|
#include "flakeref.hh"
|
|
|
|
#include <nlohmann/json_fwd.hpp>
|
|
|
|
namespace nix {
|
|
class Store;
|
|
class StorePath;
|
|
}
|
|
|
|
namespace nix::flake {
|
|
|
|
typedef std::vector<FlakeId> InputPath;
|
|
|
|
struct LockedNode;
|
|
|
|
/**
|
|
* A node in the lock file. It has outgoing edges to other nodes (its
|
|
* inputs). Only the root node has this type; all other nodes have
|
|
* type LockedNode.
|
|
*/
|
|
struct Node : std::enable_shared_from_this<Node>
|
|
{
|
|
typedef std::variant<ref<LockedNode>, InputPath> Edge;
|
|
|
|
std::map<FlakeId, Edge> inputs;
|
|
|
|
virtual ~Node() { }
|
|
};
|
|
|
|
/**
|
|
* A non-root node in the lock file.
|
|
*/
|
|
struct LockedNode : Node
|
|
{
|
|
FlakeRef lockedRef, originalRef;
|
|
bool isFlake = true;
|
|
|
|
LockedNode(
|
|
const FlakeRef & lockedRef,
|
|
const FlakeRef & originalRef,
|
|
bool isFlake = true)
|
|
: lockedRef(lockedRef), originalRef(originalRef), isFlake(isFlake)
|
|
{ }
|
|
|
|
LockedNode(const nlohmann::json & json);
|
|
|
|
StorePath computeStorePath(Store & store) const;
|
|
};
|
|
|
|
struct LockFile
|
|
{
|
|
ref<Node> root = make_ref<Node>();
|
|
|
|
LockFile() {};
|
|
LockFile(const nlohmann::json & json, const Path & path);
|
|
|
|
typedef std::map<ref<const Node>, std::string> KeyMap;
|
|
|
|
nlohmann::json toJSON() const;
|
|
|
|
std::string to_string() const;
|
|
|
|
static LockFile read(const Path & path);
|
|
|
|
void write(const Path & path) const;
|
|
|
|
/**
|
|
* Check whether this lock file has any unlocked inputs.
|
|
*/
|
|
std::optional<FlakeRef> isUnlocked() const;
|
|
|
|
bool operator ==(const LockFile & other) const;
|
|
|
|
std::shared_ptr<Node> findInput(const InputPath & path);
|
|
|
|
std::map<InputPath, Node::Edge> getAllInputs() const;
|
|
|
|
static std::string diff(const LockFile & oldLocks, const LockFile & newLocks);
|
|
|
|
/**
|
|
* Check that every 'follows' input target exists.
|
|
*/
|
|
void check();
|
|
};
|
|
|
|
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile);
|
|
|
|
InputPath parseInputPath(std::string_view s);
|
|
|
|
std::string printInputPath(const InputPath & path);
|
|
|
|
}
|