2021-03-01 05:48:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "util.hh"
|
|
|
|
#include "path.hh"
|
2021-05-17 06:45:08 +00:00
|
|
|
#include "realisation.hh"
|
2021-03-01 05:48:01 +00:00
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include <nlohmann/json_fwd.hpp>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
class Store;
|
|
|
|
|
2021-04-05 14:56:48 +00:00
|
|
|
/**
|
|
|
|
* An opaque derived path.
|
|
|
|
*
|
|
|
|
* Opaque derived paths are just store paths, and fully evaluated. They
|
|
|
|
* cannot be simplified further. Since they are opaque, they cannot be
|
|
|
|
* built, but they can fetched.
|
|
|
|
*/
|
2021-04-05 13:48:18 +00:00
|
|
|
struct DerivedPathOpaque {
|
2021-03-01 05:48:01 +00:00
|
|
|
StorePath path;
|
2021-03-02 03:50:41 +00:00
|
|
|
|
2021-03-01 05:48:01 +00:00
|
|
|
nlohmann::json toJSON(ref<Store> store) const;
|
2021-03-02 03:50:41 +00:00
|
|
|
std::string to_string(const Store & store) const;
|
2021-04-05 13:48:18 +00:00
|
|
|
static DerivedPathOpaque parse(const Store & store, std::string_view);
|
2022-03-28 12:21:35 +00:00
|
|
|
|
|
|
|
bool operator < (const DerivedPathOpaque & b) const
|
|
|
|
{ return path < b.path; }
|
2021-03-01 05:48:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-05 14:56:48 +00:00
|
|
|
/**
|
|
|
|
* A derived path that is built from a derivation
|
|
|
|
*
|
|
|
|
* Built derived paths are pair of a derivation and some output names.
|
|
|
|
* They are evaluated by building the derivation, and then replacing the
|
|
|
|
* output names with the resulting outputs.
|
|
|
|
*
|
|
|
|
* Note that does mean a derived store paths evaluates to multiple
|
|
|
|
* opaque paths, which is sort of icky as expressions are supposed to
|
|
|
|
* evaluate to single values. Perhaps this should have just a single
|
|
|
|
* output name.
|
|
|
|
*/
|
2021-04-05 13:48:18 +00:00
|
|
|
struct DerivedPathBuilt {
|
2021-03-01 05:48:01 +00:00
|
|
|
StorePath drvPath;
|
2021-04-05 13:15:25 +00:00
|
|
|
std::set<std::string> outputs;
|
2021-03-02 03:50:41 +00:00
|
|
|
|
|
|
|
std::string to_string(const Store & store) const;
|
2022-05-12 20:10:02 +00:00
|
|
|
static DerivedPathBuilt parse(const Store & store, std::string_view, std::string_view);
|
2022-03-17 10:34:31 +00:00
|
|
|
nlohmann::json toJSON(ref<Store> store) const;
|
2022-03-28 12:21:35 +00:00
|
|
|
|
|
|
|
bool operator < (const DerivedPathBuilt & b) const
|
|
|
|
{ return std::make_pair(drvPath, outputs) < std::make_pair(b.drvPath, b.outputs); }
|
2021-03-01 05:48:01 +00:00
|
|
|
};
|
|
|
|
|
2021-04-05 13:48:18 +00:00
|
|
|
using _DerivedPathRaw = std::variant<
|
|
|
|
DerivedPathOpaque,
|
|
|
|
DerivedPathBuilt
|
2021-03-02 03:50:41 +00:00
|
|
|
>;
|
|
|
|
|
2021-04-05 14:56:48 +00:00
|
|
|
/**
|
|
|
|
* A "derived path" is a very simple sort of expression that evaluates
|
|
|
|
* to (concrete) store path. It is either:
|
|
|
|
*
|
|
|
|
* - opaque, in which case it is just a concrete store path with
|
|
|
|
* possibly no known derivation
|
|
|
|
*
|
|
|
|
* - built, in which case it is a pair of a derivation path and an
|
|
|
|
* output name.
|
|
|
|
*/
|
2021-04-05 13:48:18 +00:00
|
|
|
struct DerivedPath : _DerivedPathRaw {
|
|
|
|
using Raw = _DerivedPathRaw;
|
2021-04-05 13:24:42 +00:00
|
|
|
using Raw::Raw;
|
2021-03-02 03:50:41 +00:00
|
|
|
|
2021-04-05 13:48:18 +00:00
|
|
|
using Opaque = DerivedPathOpaque;
|
|
|
|
using Built = DerivedPathBuilt;
|
|
|
|
|
2021-04-05 13:24:42 +00:00
|
|
|
inline const Raw & raw() const {
|
|
|
|
return static_cast<const Raw &>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string to_string(const Store & store) const;
|
2021-04-05 13:48:18 +00:00
|
|
|
static DerivedPath parse(const Store & store, std::string_view);
|
2021-04-05 13:24:42 +00:00
|
|
|
};
|
2021-03-02 03:50:41 +00:00
|
|
|
|
2021-04-05 14:56:48 +00:00
|
|
|
/**
|
|
|
|
* A built derived path with hints in the form of optional concrete output paths.
|
|
|
|
*
|
2021-05-12 14:19:51 +00:00
|
|
|
* See 'BuiltPath' for more an explanation.
|
2021-04-05 14:56:48 +00:00
|
|
|
*/
|
2021-05-12 14:19:51 +00:00
|
|
|
struct BuiltPathBuilt {
|
2021-04-05 13:15:25 +00:00
|
|
|
StorePath drvPath;
|
2021-05-17 06:45:08 +00:00
|
|
|
std::map<std::string, StorePath> outputs;
|
2021-04-05 13:15:25 +00:00
|
|
|
|
|
|
|
nlohmann::json toJSON(ref<Store> store) const;
|
2021-05-12 14:19:51 +00:00
|
|
|
static BuiltPathBuilt parse(const Store & store, std::string_view);
|
2021-04-05 13:15:25 +00:00
|
|
|
};
|
|
|
|
|
2021-05-12 14:19:51 +00:00
|
|
|
using _BuiltPathRaw = std::variant<
|
2021-04-05 13:48:18 +00:00
|
|
|
DerivedPath::Opaque,
|
2021-05-12 14:19:51 +00:00
|
|
|
BuiltPathBuilt
|
2021-04-05 13:15:25 +00:00
|
|
|
>;
|
2021-03-01 05:48:01 +00:00
|
|
|
|
2021-04-05 14:56:48 +00:00
|
|
|
/**
|
2021-05-17 06:45:08 +00:00
|
|
|
* A built path. Similar to a `DerivedPath`, but enriched with the corresponding
|
|
|
|
* output path(s).
|
2021-04-05 14:56:48 +00:00
|
|
|
*/
|
2021-05-12 14:19:51 +00:00
|
|
|
struct BuiltPath : _BuiltPathRaw {
|
|
|
|
using Raw = _BuiltPathRaw;
|
2021-04-05 14:05:21 +00:00
|
|
|
using Raw::Raw;
|
|
|
|
|
|
|
|
using Opaque = DerivedPathOpaque;
|
2021-05-12 14:19:51 +00:00
|
|
|
using Built = BuiltPathBuilt;
|
2021-04-05 14:05:21 +00:00
|
|
|
|
|
|
|
inline const Raw & raw() const {
|
|
|
|
return static_cast<const Raw &>(*this);
|
|
|
|
}
|
|
|
|
|
2021-05-17 06:45:08 +00:00
|
|
|
StorePathSet outPaths() const;
|
|
|
|
RealisedPath::Set toRealisedPaths(Store & store) const;
|
|
|
|
|
2021-04-05 14:05:21 +00:00
|
|
|
};
|
|
|
|
|
2021-05-17 06:45:08 +00:00
|
|
|
typedef std::vector<DerivedPath> DerivedPaths;
|
2021-05-12 14:19:51 +00:00
|
|
|
typedef std::vector<BuiltPath> BuiltPaths;
|
2021-03-01 05:48:01 +00:00
|
|
|
|
2021-05-12 14:19:51 +00:00
|
|
|
nlohmann::json derivedPathsWithHintsToJSON(const BuiltPaths & buildables, ref<Store> store);
|
2022-03-17 10:34:31 +00:00
|
|
|
nlohmann::json derivedPathsToJSON(const DerivedPaths & , ref<Store> store);
|
2021-03-01 05:48:01 +00:00
|
|
|
|
|
|
|
}
|