aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake/flakeref.hh
blob: f552c99d89bea39dcb424c37718564b3708dd22a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include "types.hh"
#include "hash.hh"

#include <variant>

namespace nix {

class Store;

namespace fetchers { struct Input; }

typedef std::string FlakeId;

struct FlakeRef
{
    std::shared_ptr<const fetchers::Input> input;

    Path subdir;

    bool operator==(const FlakeRef & other) const;

    FlakeRef(const std::shared_ptr<const fetchers::Input> & input, const Path & subdir)
        : input(input), subdir(subdir)
    {
        assert(input);
    }

    // FIXME: change to operator <<.
    std::string to_string() const;

    /* Check whether this is a "direct" flake reference, that is, not
       a flake ID, which requires a lookup in the flake registry. */
    bool isDirect() const;

    /* Check whether this is an "immutable" flake reference, that is,
       one that contains a commit hash or content hash. */
    bool isImmutable() const;

    FlakeRef resolve(ref<Store> store) const;
};

std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);

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 = {});

std::optional<std::pair<FlakeRef, std::string>> maybeParseFlakeRefWithFragment(
    const std::string & url, const std::optional<Path> & baseDir = {});

}