1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 23:28:26 -04:00
nix/src/libexpr/flake/flakeref.hh

76 lines
2.3 KiB
C++
Raw Normal View History

#pragma once
2019-02-12 12:23:11 -05:00
#include "types.hh"
#include "hash.hh"
#include "fetchers.hh"
2019-02-12 12:23:11 -05:00
#include <variant>
namespace nix {
class Store;
2019-02-12 12:23:11 -05:00
typedef std::string FlakeId;
// A flake reference specifies how to fetch a flake or raw source
// (e.g. from a Git repository). It is created from a URL-like syntax
// (e.g. 'github:NixOS/patchelf'), an attrset representation (e.g. '{
// type="github"; owner = "NixOS"; repo = "patchelf"; }'), or a local
// path.
//
// Each flake will have a number of FlakeRef objects: one for each
// input to the flake.
//
// The normal method of constructing a FlakeRef is by starting with an
// input description (usually the attrs or a url from the flake file),
// locating a fetcher for that input, and then capturing the Input
// object that fetcher generates (usually via
// FlakeRef::fromAttrs(attrs) or parseFlakeRef(url) calls).
//
// The actual fetch not have been performed yet (i.e. a FlakeRef may
// be lazy), but the fetcher can be invoked at any time via the
// FlakeRef to ensure the store is populated with this input.
2019-02-12 12:23:11 -05:00
struct FlakeRef
{
// fetcher-specific representation of the input, sufficient to
// perform the fetch operation.
fetchers::Input input;
2019-02-12 12:23:11 -05:00
// sub-path within the fetched input that represents this input
Path subdir;
2019-02-12 12:23:11 -05:00
bool operator==(const FlakeRef & other) const;
2019-04-08 13:03:00 -04:00
FlakeRef(fetchers::Input && input, const Path & subdir)
: input(std::move(input)), subdir(subdir)
{ }
2019-02-12 12:23:11 -05:00
// FIXME: change to operator <<.
std::string to_string() const;
2020-03-17 15:54:36 -04:00
fetchers::Attrs toAttrs() const;
FlakeRef resolve(ref<Store> store) const;
2020-03-17 15:54:36 -04:00
static FlakeRef fromAttrs(const fetchers::Attrs & attrs);
2020-02-02 05:31:58 -05:00
std::pair<fetchers::Tree, FlakeRef> fetchTree(ref<Store> store) const;
2019-03-10 01:05:05 -05:00
};
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
FlakeRef parseFlakeRef(
const std::string & url, const std::optional<Path> & baseDir = {}, bool allowMissing = false);
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 = {}, bool allowMissing = false);
std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment(
const std::string & url, const std::optional<Path> & baseDir = {});
2019-02-12 12:23:11 -05:00
}