2020-03-30 17:04:18 +03:00
|
|
|
#include "fetchers.hh"
|
|
|
|
#include "store-api.hh"
|
2023-10-24 11:23:46 +03:00
|
|
|
#include "input-accessor.hh"
|
2020-03-30 17:04:18 +03:00
|
|
|
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
namespace nix::fetchers {
|
|
|
|
|
2023-10-30 16:14:27 +02:00
|
|
|
using InputSchemeMap = std::map<std::string_view, std::shared_ptr<InputScheme>>;
|
|
|
|
|
|
|
|
std::unique_ptr<InputSchemeMap> inputSchemes = nullptr;
|
2020-03-30 17:04:18 +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
|
|
|
void registerInputScheme(std::shared_ptr<InputScheme> && inputScheme)
|
2020-03-30 17:04:18 +03:00
|
|
|
{
|
2023-10-30 16:14:27 +02:00
|
|
|
if (!inputSchemes)
|
|
|
|
inputSchemes = std::make_unique<InputSchemeMap>();
|
|
|
|
auto schemeName = inputScheme->schemeName();
|
|
|
|
if (inputSchemes->count(schemeName) > 0)
|
|
|
|
throw Error("Input scheme with name %s already registered", schemeName);
|
|
|
|
inputSchemes->insert_or_assign(schemeName, std::move(inputScheme));
|
2020-03-30 17:04:18 +03:00
|
|
|
}
|
|
|
|
|
2023-10-30 16:30:59 +02:00
|
|
|
nlohmann::json dumpRegisterInputSchemeInfo() {
|
|
|
|
using nlohmann::json;
|
|
|
|
|
|
|
|
auto res = json::object();
|
|
|
|
|
|
|
|
for (auto & [name, scheme] : *inputSchemes) {
|
|
|
|
auto & r = res[name] = json::object();
|
|
|
|
r["allowedAttrs"] = scheme->allowedAttrs();
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2020-03-30 17:04:18 +03:00
|
|
|
}
|
|
|
|
|
2023-08-01 17:07:20 +03:00
|
|
|
Input Input::fromURL(const std::string & url, bool requireTree)
|
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
|
|
|
{
|
2023-08-01 17:07:20 +03:00
|
|
|
return fromURL(parseURL(url), requireTree);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void fixupInput(Input & input)
|
|
|
|
{
|
|
|
|
// Check common attributes.
|
|
|
|
input.getType();
|
|
|
|
input.getRef();
|
|
|
|
if (input.getRev())
|
2022-02-24 19:09:00 +02:00
|
|
|
input.locked = true;
|
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
|
|
|
input.getRevCount();
|
|
|
|
input.getLastModified();
|
|
|
|
if (input.getNarHash())
|
2022-02-24 19:09:00 +02:00
|
|
|
input.locked = true;
|
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
|
|
|
}
|
|
|
|
|
2023-08-01 17:07:20 +03:00
|
|
|
Input Input::fromURL(const ParsedURL & url, bool requireTree)
|
2020-03-30 17:04:18 +03:00
|
|
|
{
|
2023-10-30 16:14:27 +02:00
|
|
|
for (auto & [_, inputScheme] : *inputSchemes) {
|
2023-08-01 17:07:20 +03:00
|
|
|
auto res = inputScheme->inputFromURL(url, requireTree);
|
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
|
|
|
if (res) {
|
2023-09-29 04:21:58 +03:00
|
|
|
experimentalFeatureSettings.require(inputScheme->experimentalFeature());
|
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
|
|
|
res->scheme = inputScheme;
|
|
|
|
fixupInput(*res);
|
|
|
|
return std::move(*res);
|
|
|
|
}
|
2020-03-30 17:04:18 +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
|
|
|
throw Error("input '%s' is unsupported", url.url);
|
2020-03-30 17:04:18 +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
|
|
|
Input Input::fromAttrs(Attrs && attrs)
|
2020-03-30 17:04:18 +03:00
|
|
|
{
|
2023-10-30 16:14:27 +02:00
|
|
|
auto schemeName = ({
|
|
|
|
auto schemeNameOpt = maybeGetStrAttr(attrs, "type");
|
|
|
|
if (!schemeNameOpt)
|
|
|
|
throw Error("'type' attribute to specify input scheme is required but not provided");
|
|
|
|
*std::move(schemeNameOpt);
|
|
|
|
});
|
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
|
|
|
|
2023-10-30 16:14:27 +02:00
|
|
|
auto raw = [&]() {
|
|
|
|
// Return an input without a scheme; most operations will fail,
|
|
|
|
// but not all of them. Doing this is to support those other
|
|
|
|
// operations which are supposed to be robust on
|
|
|
|
// unknown/uninterpretable inputs.
|
|
|
|
Input input;
|
|
|
|
input.attrs = attrs;
|
|
|
|
fixupInput(input);
|
|
|
|
return input;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::shared_ptr<InputScheme> inputScheme = ({
|
|
|
|
auto i = inputSchemes->find(schemeName);
|
|
|
|
i == inputSchemes->end() ? nullptr : i->second;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!inputScheme) return raw();
|
|
|
|
|
|
|
|
experimentalFeatureSettings.require(inputScheme->experimentalFeature());
|
|
|
|
|
|
|
|
auto allowedAttrs = inputScheme->allowedAttrs();
|
|
|
|
|
|
|
|
for (auto & [name, _] : attrs)
|
|
|
|
if (name != "type" && allowedAttrs.count(name) == 0)
|
|
|
|
throw Error("input attribute '%s' not supported by scheme '%s'", name, schemeName);
|
|
|
|
|
|
|
|
auto res = inputScheme->inputFromAttrs(attrs);
|
|
|
|
if (!res) return raw();
|
|
|
|
res->scheme = inputScheme;
|
|
|
|
fixupInput(*res);
|
|
|
|
return std::move(*res);
|
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
|
|
|
}
|
|
|
|
|
2023-11-20 21:04:37 +02:00
|
|
|
std::optional<std::string> Input::getFingerprint(ref<Store> store) const
|
|
|
|
{
|
|
|
|
return scheme ? scheme->getFingerprint(store, *this) : std::nullopt;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
ParsedURL Input::toURL() const
|
|
|
|
{
|
|
|
|
if (!scheme)
|
2020-10-28 16:41:18 +02:00
|
|
|
throw Error("cannot show unsupported input '%s'", attrsToJSON(attrs));
|
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
|
|
|
return scheme->toURL(*this);
|
|
|
|
}
|
|
|
|
|
2020-09-30 00:33:16 +03:00
|
|
|
std::string Input::toURLString(const std::map<std::string, std::string> & extraQuery) const
|
|
|
|
{
|
|
|
|
auto url = toURL();
|
|
|
|
for (auto & attr : extraQuery)
|
|
|
|
url.query.insert(attr);
|
|
|
|
return url.to_string();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
std::string Input::to_string() const
|
|
|
|
{
|
|
|
|
return toURL().to_string();
|
2020-03-30 17:04:18 +03:00
|
|
|
}
|
|
|
|
|
2023-10-20 20:13:35 +03:00
|
|
|
bool Input::isDirect() const
|
|
|
|
{
|
|
|
|
return !scheme || scheme->isDirect(*this);
|
|
|
|
}
|
|
|
|
|
2020-03-30 17:04:18 +03:00
|
|
|
Attrs Input::toAttrs() const
|
|
|
|
{
|
|
|
|
return attrs;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
bool Input::operator ==(const Input & other) const
|
|
|
|
{
|
|
|
|
return attrs == other.attrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Input::contains(const Input & other) const
|
|
|
|
{
|
2020-06-09 14:45:07 +03:00
|
|
|
if (*this == other) return true;
|
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
|
|
|
auto other2(other);
|
|
|
|
other2.attrs.erase("ref");
|
|
|
|
other2.attrs.erase("rev");
|
|
|
|
if (*this == other2) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-10-20 20:50:21 +03:00
|
|
|
std::pair<StorePath, Input> Input::fetch(ref<Store> store) const
|
2020-03-30 17:04:18 +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
|
|
|
if (!scheme)
|
2020-10-28 16:41:18 +02:00
|
|
|
throw Error("cannot fetch unsupported input '%s'", attrsToJSON(toAttrs()));
|
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
|
|
|
|
2020-05-30 02:16:53 +03:00
|
|
|
/* The tree may already be in the Nix store, or it could be
|
|
|
|
substituted (which is often faster than fetching from the
|
|
|
|
original source). So check that. */
|
2023-10-20 18:18:42 +03:00
|
|
|
if (getNarHash()) {
|
2020-05-30 02:16:53 +03:00
|
|
|
try {
|
|
|
|
auto storePath = computeStorePath(*store);
|
|
|
|
|
|
|
|
store->ensurePath(storePath);
|
|
|
|
|
|
|
|
debug("using substituted/cached input '%s' in '%s'",
|
|
|
|
to_string(), store->printStorePath(storePath));
|
|
|
|
|
2023-10-20 20:50:21 +03:00
|
|
|
return {std::move(storePath), *this};
|
2020-05-30 02:16:53 +03:00
|
|
|
} catch (Error & e) {
|
|
|
|
debug("substitution of input '%s' failed: %s", to_string(), e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-15 15:33:31 +02:00
|
|
|
auto [storePath, input] = [&]() -> std::pair<StorePath, Input> {
|
2021-01-27 15:02:54 +02:00
|
|
|
try {
|
|
|
|
return scheme->fetch(store, *this);
|
|
|
|
} catch (Error & e) {
|
|
|
|
e.addTrace({}, "while fetching the input '%s'", to_string());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}();
|
2020-03-30 17:04:18 +03:00
|
|
|
|
2023-10-20 20:50:21 +03:00
|
|
|
auto narHash = store->queryPathInfo(storePath)->narHash;
|
2023-10-13 04:48:15 +03:00
|
|
|
input.attrs.insert_or_assign("narHash", narHash.to_string(HashFormat::SRI, true));
|
2020-01-21 17:27:53 +02:00
|
|
|
|
2020-05-30 01:59:13 +03:00
|
|
|
if (auto prevNarHash = getNarHash()) {
|
|
|
|
if (narHash != *prevNarHash)
|
2020-04-29 23:39:58 +03:00
|
|
|
throw Error((unsigned int) 102, "NAR hash mismatch in input '%s' (%s), expected '%s', got '%s'",
|
2023-10-20 20:50:21 +03:00
|
|
|
to_string(),
|
|
|
|
store->printStorePath(storePath),
|
|
|
|
prevNarHash->to_string(HashFormat::SRI, true),
|
|
|
|
narHash.to_string(HashFormat::SRI, true));
|
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
|
|
|
}
|
2020-03-30 17:04:18 +03:00
|
|
|
|
2020-05-30 01:59:13 +03:00
|
|
|
if (auto prevLastModified = getLastModified()) {
|
|
|
|
if (input.getLastModified() != prevLastModified)
|
|
|
|
throw Error("'lastModified' attribute mismatch in input '%s', expected %d",
|
|
|
|
input.to_string(), *prevLastModified);
|
|
|
|
}
|
2020-03-30 17:04:18 +03:00
|
|
|
|
2023-06-07 16:06:12 +03:00
|
|
|
if (auto prevRev = getRev()) {
|
|
|
|
if (input.getRev() != prevRev)
|
|
|
|
throw Error("'rev' attribute mismatch in input '%s', expected %s",
|
|
|
|
input.to_string(), prevRev->gitRev());
|
|
|
|
}
|
|
|
|
|
2020-05-30 01:59:13 +03:00
|
|
|
if (auto prevRevCount = getRevCount()) {
|
|
|
|
if (input.getRevCount() != prevRevCount)
|
|
|
|
throw Error("'revCount' attribute mismatch in input '%s', expected %d",
|
|
|
|
input.to_string(), *prevRevCount);
|
|
|
|
}
|
2020-03-30 17:04:18 +03:00
|
|
|
|
2022-02-24 19:09:00 +02:00
|
|
|
input.locked = true;
|
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
|
|
|
|
2023-10-20 20:50:21 +03:00
|
|
|
return {std::move(storePath), input};
|
2020-03-30 17:04:18 +03:00
|
|
|
}
|
|
|
|
|
2023-11-14 16:52:18 +02:00
|
|
|
std::pair<ref<InputAccessor>, Input> Input::getAccessor(ref<Store> store) const
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return scheme->getAccessor(store, *this);
|
|
|
|
} catch (Error & e) {
|
|
|
|
e.addTrace({}, "while fetching the input '%s'", to_string());
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Input Input::applyOverrides(
|
2020-01-21 17:27:53 +02:00
|
|
|
std::optional<std::string> ref,
|
|
|
|
std::optional<Hash> rev) const
|
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
|
|
|
{
|
|
|
|
if (!scheme) return *this;
|
|
|
|
return scheme->applyOverrides(*this, ref, rev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Input::clone(const Path & destDir) const
|
|
|
|
{
|
|
|
|
assert(scheme);
|
|
|
|
scheme->clone(*this, destDir);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<Path> Input::getSourcePath() const
|
|
|
|
{
|
|
|
|
assert(scheme);
|
|
|
|
return scheme->getSourcePath(*this);
|
|
|
|
}
|
|
|
|
|
2023-10-25 19:18:15 +03:00
|
|
|
void Input::putFile(
|
|
|
|
const CanonPath & path,
|
|
|
|
std::string_view contents,
|
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
|
|
|
std::optional<std::string> commitMsg) const
|
|
|
|
{
|
|
|
|
assert(scheme);
|
2023-10-25 19:18:15 +03:00
|
|
|
return scheme->putFile(*this, path, contents, commitMsg);
|
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
|
|
|
}
|
|
|
|
|
2021-07-05 14:09:46 +03:00
|
|
|
std::string Input::getName() const
|
|
|
|
{
|
|
|
|
return maybeGetStrAttr(attrs, "name").value_or("source");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
StorePath Input::computeStorePath(Store & store) const
|
|
|
|
{
|
|
|
|
auto narHash = getNarHash();
|
|
|
|
if (!narHash)
|
2022-02-24 19:09:00 +02:00
|
|
|
throw Error("cannot compute store path for unlocked input '%s'", to_string());
|
2021-10-01 01:36:50 +03:00
|
|
|
return store.makeFixedOutputPath(getName(), FixedOutputInfo {
|
2023-07-06 01:53:44 +03:00
|
|
|
.method = FileIngestionMethod::Recursive,
|
|
|
|
.hash = *narHash,
|
2023-02-28 18:57:20 +02:00
|
|
|
.references = {},
|
2020-10-07 16:52:20 +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
|
|
|
}
|
|
|
|
|
|
|
|
std::string Input::getType() const
|
|
|
|
{
|
|
|
|
return getStrAttr(attrs, "type");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<Hash> Input::getNarHash() const
|
|
|
|
{
|
2020-07-16 20:28:52 +03:00
|
|
|
if (auto s = maybeGetStrAttr(attrs, "narHash")) {
|
|
|
|
auto hash = s->empty() ? Hash(htSHA256) : Hash::parseSRI(*s);
|
|
|
|
if (hash.type != htSHA256)
|
2020-08-01 19:22:50 +03:00
|
|
|
throw UsageError("narHash must use SHA-256");
|
|
|
|
return hash;
|
2020-07-16 20:28:52 +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
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<std::string> Input::getRef() const
|
|
|
|
{
|
|
|
|
if (auto s = maybeGetStrAttr(attrs, "ref"))
|
|
|
|
return *s;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<Hash> Input::getRev() const
|
|
|
|
{
|
2022-04-06 20:28:12 +03:00
|
|
|
std::optional<Hash> hash = {};
|
|
|
|
|
|
|
|
if (auto s = maybeGetStrAttr(attrs, "rev")) {
|
|
|
|
try {
|
|
|
|
hash = Hash::parseAnyPrefixed(*s);
|
|
|
|
} catch (BadHash &e) {
|
2023-09-29 04:10:17 +03:00
|
|
|
// Default to sha1 for backwards compatibility with existing
|
|
|
|
// usages (e.g. `builtins.fetchTree` calls or flake inputs).
|
2022-04-06 20:28:12 +03:00
|
|
|
hash = Hash::parseAny(*s, htSHA1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<uint64_t> Input::getRevCount() const
|
|
|
|
{
|
|
|
|
if (auto n = maybeGetIntAttr(attrs, "revCount"))
|
|
|
|
return *n;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<time_t> Input::getLastModified() const
|
|
|
|
{
|
|
|
|
if (auto n = maybeGetIntAttr(attrs, "lastModified"))
|
|
|
|
return *n;
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-12-07 13:58:58 +02:00
|
|
|
ParsedURL InputScheme::toURL(const Input & input) const
|
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
|
|
|
{
|
2020-10-28 16:41:18 +02:00
|
|
|
throw Error("don't know how to convert input '%s' to a URL", attrsToJSON(input.attrs));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Input InputScheme::applyOverrides(
|
|
|
|
const Input & input,
|
|
|
|
std::optional<std::string> ref,
|
2022-12-07 13:58:58 +02:00
|
|
|
std::optional<Hash> rev) const
|
2020-01-21 17:27:53 +02:00
|
|
|
{
|
|
|
|
if (ref)
|
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
|
|
|
throw Error("don't know how to set branch/tag name of input '%s' to '%s'", input.to_string(), *ref);
|
2020-01-21 17:27:53 +02:00
|
|
|
if (rev)
|
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
|
|
|
throw Error("don't know how to set revision of input '%s' to '%s'", input.to_string(), rev->gitRev());
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
2023-10-25 19:18:15 +03:00
|
|
|
std::optional<Path> InputScheme::getSourcePath(const Input & input) const
|
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
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-10-25 19:18:15 +03:00
|
|
|
void InputScheme::putFile(
|
|
|
|
const Input & input,
|
|
|
|
const CanonPath & path,
|
|
|
|
std::string_view contents,
|
|
|
|
std::optional<std::string> commitMsg) const
|
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
|
|
|
{
|
2023-10-25 19:18:15 +03:00
|
|
|
throw Error("input '%s' does not support modifying file '%s'", input.to_string(), path);
|
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
|
|
|
}
|
|
|
|
|
2022-12-07 13:58:58 +02:00
|
|
|
void InputScheme::clone(const Input & input, const Path & destDir) const
|
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
|
|
|
{
|
|
|
|
throw Error("do not know how to clone input '%s'", input.to_string());
|
2020-01-21 17:27:53 +02:00
|
|
|
}
|
|
|
|
|
2023-10-24 11:23:46 +03:00
|
|
|
std::pair<StorePath, Input> InputScheme::fetch(ref<Store> store, const Input & input)
|
|
|
|
{
|
|
|
|
auto [accessor, input2] = getAccessor(store, input);
|
|
|
|
auto storePath = accessor->root().fetchToStore(store, input2.getName());
|
|
|
|
return {storePath, input2};
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<ref<InputAccessor>, Input> InputScheme::getAccessor(ref<Store> store, const Input & input) const
|
|
|
|
{
|
|
|
|
throw UnimplementedError("InputScheme must implement fetch() or getAccessor()");
|
|
|
|
}
|
|
|
|
|
2023-10-30 16:14:27 +02:00
|
|
|
std::optional<ExperimentalFeature> InputScheme::experimentalFeature() const
|
2023-09-29 04:21:58 +03:00
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-10-20 22:16:56 +03:00
|
|
|
std::string publicKeys_to_string(const std::vector<PublicKey>& publicKeys)
|
|
|
|
{
|
|
|
|
return ((nlohmann::json) publicKeys).dump();
|
|
|
|
}
|
|
|
|
|
2020-03-30 17:04:18 +03:00
|
|
|
}
|