mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-24 14:56:15 +02:00
071dd2b3a4
It's better to just check whether the input has all the attributes needed to consider itself locked (e.g. whether a Git input has an 'rev' attribute). Also, the 'locked' field was actually incorrect for Git inputs: it would be set to true even for dirty worktrees. As a result, we got away with using fetchTree() internally even though fetchTree() requires a locked input in pure mode. In particular, this allowed '--override-input' to work by accident. The fix is to pass a set of "overrides" to call-flake.nix for all the unlocked inputs (i.e. the top-level flake and any --override-inputs).
97 lines
2.2 KiB
C++
97 lines
2.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;
|
|
|
|
std::pair<nlohmann::json, KeyMap> toJSON() const;
|
|
|
|
std::pair<std::string, KeyMap> to_string() const;
|
|
|
|
static LockFile read(const Path & path);
|
|
|
|
/**
|
|
* Check whether this lock file has any unlocked inputs. If so,
|
|
* return one.
|
|
*/
|
|
std::optional<FlakeRef> isUnlocked() const;
|
|
|
|
bool operator ==(const LockFile & other) const;
|
|
// Needed for old gcc versions that don't synthesize it (like gcc 8.2.2
|
|
// that is still the default on aarch64-linux)
|
|
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);
|
|
|
|
}
|