#pragma once #include "types.hh" #include "hash.hh" #include "path.hh" #include "tree-info.hh" #include "attrs.hh" #include "url.hh" #include namespace nix { class Store; } namespace nix::fetchers { struct Input; struct Tree { Path actualPath; StorePath storePath; TreeInfo info; }; struct Input : std::enable_shared_from_this { std::optional narHash; // FIXME: implement virtual std::string type() const = 0; virtual ~Input() { } virtual bool operator ==(const Input & other) const { return false; } /* Check whether this is a "direct" input, that is, not one that goes through a registry. */ virtual bool isDirect() const { return true; } /* Check whether this is an "immutable" input, that is, one that contains a commit hash or content hash. */ virtual bool isImmutable() const { return (bool) narHash; } virtual bool contains(const Input & other) const { return false; } virtual std::optional getRef() const { return {}; } virtual std::optional getRev() const { return {}; } virtual ParsedURL toURL() const = 0; std::string to_string() const { return toURL().to_string(); } Attrs toAttrs() const; std::pair> fetchTree(ref store) const; virtual std::shared_ptr applyOverrides( std::optional ref, std::optional rev) const; virtual std::optional getSourcePath() const { return {}; } virtual void markChangedFile( std::string_view file, std::optional commitMsg) const { assert(false); } virtual void clone(const Path & destDir) const { throw Error("do not know how to clone input '%s'", to_string()); } private: virtual std::pair> fetchTreeInternal(ref store) const = 0; virtual Attrs toAttrsInternal() const = 0; }; struct InputScheme { virtual ~InputScheme() { } virtual std::unique_ptr inputFromURL(const ParsedURL & url) = 0; virtual std::unique_ptr inputFromAttrs(const Attrs & attrs) = 0; }; std::unique_ptr inputFromURL(const ParsedURL & url); std::unique_ptr inputFromURL(const std::string & url); std::unique_ptr inputFromAttrs(const Attrs & attrs); void registerInputScheme(std::unique_ptr && fetcher); struct DownloadFileResult { StorePath storePath; std::string etag; std::string effectiveUrl; }; DownloadFileResult downloadFile( ref store, const std::string & url, const std::string & name, bool immutable); Tree downloadTarball( ref store, const std::string & url, const std::string & name, bool immutable); }