2019-04-19 12:43:56 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-02-12 19:23:11 +02:00
|
|
|
#include "types.hh"
|
|
|
|
#include "hash.hh"
|
2020-01-31 20:16:40 +02:00
|
|
|
#include "fetchers/fetchers.hh"
|
2019-02-12 19:23:11 +02:00
|
|
|
|
|
|
|
#include <variant>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
class Store;
|
2019-02-12 19:23:11 +02:00
|
|
|
|
|
|
|
typedef std::string FlakeId;
|
|
|
|
|
|
|
|
struct FlakeRef
|
|
|
|
{
|
2020-01-21 17:27:53 +02:00
|
|
|
std::shared_ptr<const fetchers::Input> input;
|
2019-02-12 19:23:11 +02:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
Path subdir;
|
2019-02-12 19:23:11 +02:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
bool operator==(const FlakeRef & other) const;
|
2019-04-08 20:03:00 +03:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
FlakeRef(const std::shared_ptr<const fetchers::Input> & input, const Path & subdir)
|
|
|
|
: input(input), subdir(subdir)
|
2019-04-08 20:03:00 +03:00
|
|
|
{
|
2020-01-21 17:27:53 +02:00
|
|
|
assert(input);
|
2019-04-08 20:03:00 +03:00
|
|
|
}
|
2019-02-21 07:53:01 +02:00
|
|
|
|
2019-02-12 19:23:11 +02:00
|
|
|
// FIXME: change to operator <<.
|
|
|
|
std::string to_string() const;
|
|
|
|
|
2020-01-31 20:16:40 +02:00
|
|
|
fetchers::Input::Attrs toAttrs() const;
|
|
|
|
|
2019-02-12 19:23:11 +02:00
|
|
|
/* Check whether this is a "direct" flake reference, that is, not
|
|
|
|
a flake ID, which requires a lookup in the flake registry. */
|
2020-01-21 17:27:53 +02:00
|
|
|
bool isDirect() const;
|
2019-02-12 19:23:11 +02:00
|
|
|
|
|
|
|
/* Check whether this is an "immutable" flake reference, that is,
|
|
|
|
one that contains a commit hash or content hash. */
|
2019-02-12 22:05:44 +02:00
|
|
|
bool isImmutable() const;
|
2019-02-12 19:23:11 +02:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
FlakeRef resolve(ref<Store> store) const;
|
2020-01-31 20:16:40 +02:00
|
|
|
|
|
|
|
static FlakeRef fromAttrs(const fetchers::Input::Attrs & attrs);
|
2019-03-10 08:05:05 +02:00
|
|
|
};
|
2019-04-19 12:43:56 +03:00
|
|
|
|
|
|
|
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
FlakeRef parseFlakeRef(
|
|
|
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
|
|
|
|
|
|
|
std::optional<FlakeRef> maybeParseFlake(
|
|
|
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
|
|
|
|
|
|
|
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
|
|
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
2019-05-31 21:53:23 +03:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment(
|
|
|
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
2019-05-31 21:53:23 +03:00
|
|
|
|
2019-02-12 19:23:11 +02:00
|
|
|
}
|