2019-04-19 12:43:56 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2019-04-19 12:43:56 +03:00
|
|
|
|
2019-02-12 19:23:11 +02:00
|
|
|
#include "types.hh"
|
|
|
|
#include "hash.hh"
|
2020-03-30 15:03:28 +03:00
|
|
|
#include "fetchers.hh"
|
2023-01-10 18:27:19 +02:00
|
|
|
#include "outputs-spec.hh"
|
2019-02-12 19:23:11 +02:00
|
|
|
|
2023-09-29 03:55:41 +03:00
|
|
|
#include <regex>
|
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;
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* A flake reference specifies how to fetch a flake or raw source
|
2020-09-28 19:37:26 +03:00
|
|
|
* (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).
|
|
|
|
*
|
2022-08-04 10:45:28 +03:00
|
|
|
* The actual fetch may not have been performed yet (i.e. a FlakeRef may
|
2020-09-28 19:37:26 +03:00
|
|
|
* 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 19:23:11 +02:00
|
|
|
struct FlakeRef
|
|
|
|
{
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Fetcher-specific representation of the input, sufficient to
|
|
|
|
* perform the fetch operation.
|
|
|
|
*/
|
Remove TreeInfo
The attributes previously stored in TreeInfo (narHash, revCount,
lastModified) are now stored in Input. This makes it less arbitrary
what attributes are stored where.
As a result, the lock file format has changed. An entry like
"info": {
"lastModified": 1585405475,
"narHash": "sha256-bESW0n4KgPmZ0luxvwJ+UyATrC6iIltVCsGdLiphVeE="
},
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b88ff468e9850410070d4e0ccd68c7011f15b2be",
"type": "github"
},
is now stored as
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b88ff468e9850410070d4e0ccd68c7011f15b2be",
"type": "github",
"lastModified": 1585405475,
"narHash": "sha256-bESW0n4KgPmZ0luxvwJ+UyATrC6iIltVCsGdLiphVeE="
},
The 'Input' class is now a dumb set of attributes. All the fetcher
implementations subclass InputScheme, not Input. This simplifies the
API.
Also, fix substitution of flake inputs. This was broken since lazy
flake fetching started using fetchTree internally.
2020-05-30 01:44:11 +03:00
|
|
|
fetchers::Input input;
|
2019-02-12 19:23:11 +02:00
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* sub-path within the fetched input that represents this input
|
|
|
|
*/
|
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
|
|
|
|
Remove TreeInfo
The attributes previously stored in TreeInfo (narHash, revCount,
lastModified) are now stored in Input. This makes it less arbitrary
what attributes are stored where.
As a result, the lock file format has changed. An entry like
"info": {
"lastModified": 1585405475,
"narHash": "sha256-bESW0n4KgPmZ0luxvwJ+UyATrC6iIltVCsGdLiphVeE="
},
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b88ff468e9850410070d4e0ccd68c7011f15b2be",
"type": "github"
},
is now stored as
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b88ff468e9850410070d4e0ccd68c7011f15b2be",
"type": "github",
"lastModified": 1585405475,
"narHash": "sha256-bESW0n4KgPmZ0luxvwJ+UyATrC6iIltVCsGdLiphVeE="
},
The 'Input' class is now a dumb set of attributes. All the fetcher
implementations subclass InputScheme, not Input. This simplifies the
API.
Also, fix substitution of flake inputs. This was broken since lazy
flake fetching started using fetchTree internally.
2020-05-30 01:44:11 +03:00
|
|
|
FlakeRef(fetchers::Input && input, const Path & subdir)
|
|
|
|
: input(std::move(input)), subdir(subdir)
|
|
|
|
{ }
|
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-03-17 21:54:36 +02:00
|
|
|
fetchers::Attrs toAttrs() const;
|
2020-01-31 20:16:40 +02:00
|
|
|
|
2020-01-21 17:27:53 +02:00
|
|
|
FlakeRef resolve(ref<Store> store) const;
|
2020-01-31 20:16:40 +02:00
|
|
|
|
2020-03-17 21:54:36 +02:00
|
|
|
static FlakeRef fromAttrs(const fetchers::Attrs & attrs);
|
2020-02-02 12:31:58 +02:00
|
|
|
|
2023-10-20 20:50:21 +03:00
|
|
|
std::pair<StorePath, FlakeRef> fetchTree(ref<Store> store) const;
|
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);
|
|
|
|
|
2024-04-19 19:54:31 +03:00
|
|
|
/**
|
|
|
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
|
|
|
*/
|
2020-01-21 17:27:53 +02:00
|
|
|
FlakeRef parseFlakeRef(
|
2021-12-13 21:54:43 +02:00
|
|
|
const std::string & url,
|
|
|
|
const std::optional<Path> & baseDir = {},
|
|
|
|
bool allowMissing = false,
|
|
|
|
bool isFlake = true);
|
2020-01-21 17:27:53 +02:00
|
|
|
|
2024-04-19 19:54:31 +03:00
|
|
|
/**
|
|
|
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
|
|
|
*/
|
2020-01-21 17:27:53 +02:00
|
|
|
std::optional<FlakeRef> maybeParseFlake(
|
|
|
|
const std::string & url, const std::optional<Path> & baseDir = {});
|
|
|
|
|
2024-04-19 19:54:31 +03:00
|
|
|
/**
|
|
|
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
|
|
|
*/
|
2020-01-21 17:27:53 +02:00
|
|
|
std::pair<FlakeRef, std::string> parseFlakeRefWithFragment(
|
2021-12-13 21:54:43 +02:00
|
|
|
const std::string & url,
|
|
|
|
const std::optional<Path> & baseDir = {},
|
|
|
|
bool allowMissing = false,
|
|
|
|
bool isFlake = true);
|
2019-05-31 21:53:23 +03:00
|
|
|
|
2024-04-19 19:54:31 +03:00
|
|
|
/**
|
|
|
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
|
|
|
*/
|
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
|
|
|
|
2024-04-19 19:54:31 +03:00
|
|
|
/**
|
|
|
|
* @param baseDir Optional [base directory](https://nixos.org/manual/nix/unstable/glossary#gloss-base-directory)
|
|
|
|
*/
|
2023-01-11 09:00:44 +02:00
|
|
|
std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
|
2022-04-22 16:17:01 +03:00
|
|
|
const std::string & url,
|
|
|
|
const std::optional<Path> & baseDir = {},
|
|
|
|
bool allowMissing = false,
|
|
|
|
bool isFlake = true);
|
|
|
|
|
2023-09-29 03:55:41 +03:00
|
|
|
const static std::string flakeIdRegexS = "[a-zA-Z][a-zA-Z0-9_-]*";
|
|
|
|
extern std::regex flakeIdRegex;
|
2022-04-22 16:17:01 +03:00
|
|
|
|
2019-02-12 19:23:11 +02:00
|
|
|
}
|