split <2.34 code in meson

This commit is contained in:
atagen 2026-04-23 22:28:42 +10:00
parent 55c173bd44
commit 7fbcc8744d
3 changed files with 78 additions and 1 deletions

View file

@ -11,6 +11,13 @@ nix_util = dependency('nix-util')
nix_store = dependency('nix-store')
nlohmann_json = dependency('nlohmann_json', version : '>=3.9')
if nix_fetchers.version().version_compare('<2.34')
add_project_arguments('-DNIX_PRE_234', language : 'cpp')
message('Using pre-2.34 Nix fetcher API (nix-fetchers @ ' + nix_fetchers.version() + ')')
else
message('Using post-2.34 Nix fetcher API (nix-fetchers @ ' + nix_fetchers.version() + ')')
endif
plugin = shared_library('nix-shorturl-plugin',
'src/plugin.cc',
'src/shorturl-scheme.cc',

View file

@ -25,7 +25,11 @@ ShortUrlInputScheme::inputFromURL(
if (!config.hasScheme(url.scheme))
return std::nullopt;
#ifdef NIX_PRE_234
auto expanded = config.expand(url.scheme, url.path, url.query, url.fragment);
#else
auto expanded = config.expand(url.scheme, url.renderPath(), url.query, url.fragment);
#endif
if (!expanded)
return std::nullopt;
@ -49,6 +53,55 @@ ShortUrlInputScheme::inputFromAttrs(
return std::nullopt;
}
#ifdef NIX_PRE_234
StringSet ShortUrlInputScheme::allowedAttrs() const
{
return {};
}
std::pair<nix::ref<SourceAccessor>, nix::fetchers::Input>
ShortUrlInputScheme::getAccessor(nix::ref<Store> store, const nix::fetchers::Input & input) const
{
// Reconstruct the real Input from the stored attrs (which have the real type).
// Call the real scheme's getAccessor directly to avoid double fingerprint assignment
// in Input::getAccessorUnchecked.
auto attrs = input.toAttrs();
auto realInput = nix::fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
return realInput.scheme->getAccessor(store, realInput);
}
bool ShortUrlInputScheme::isLocked(const nix::fetchers::Input & input) const
{
auto attrs = input.toAttrs();
auto realInput = nix::fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
return realInput.isLocked();
}
std::optional<std::string>
ShortUrlInputScheme::getFingerprint(nix::ref<Store> store, const nix::fetchers::Input & input) const
{
auto attrs = input.toAttrs();
auto realInput = nix::fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
return realInput.getFingerprint(store);
}
ParsedURL ShortUrlInputScheme::toURL(const nix::fetchers::Input & input) const
{
auto attrs = input.toAttrs();
auto realInput = nix::fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
return realInput.toURL();
}
bool ShortUrlInputScheme::isDirect(const nix::fetchers::Input & input) const
{
auto attrs = input.toAttrs();
auto realInput = nix::fetchers::Input::fromAttrs(*input.settings, std::move(attrs));
return realInput.isDirect();
}
#else
std::string ShortUrlInputScheme::schemeDescription() const
{
return "Short URL scheme expansion";
@ -79,4 +132,6 @@ bool ShortUrlInputScheme::isLocked(const nix::fetchers::Settings & settings, con
return realInput.isLocked(settings);
}
#endif
} // namespace nix::shorturl

View file

@ -25,6 +25,21 @@ struct ShortUrlInputScheme : nix::fetchers::InputScheme
const nix::fetchers::Settings & settings,
const nix::fetchers::Attrs & attrs) const override;
#ifdef NIX_PRE_234
StringSet allowedAttrs() const override;
std::pair<nix::ref<SourceAccessor>, nix::fetchers::Input>
getAccessor(nix::ref<Store> store, const nix::fetchers::Input & input) const override;
bool isLocked(const nix::fetchers::Input & input) const override;
std::optional<std::string>
getFingerprint(nix::ref<Store> store, const nix::fetchers::Input & input) const override;
ParsedURL toURL(const nix::fetchers::Input & input) const override;
bool isDirect(const nix::fetchers::Input & input) const override;
#else
std::string schemeDescription() const override;
const std::map<std::string, nix::fetchers::InputScheme::AttributeInfo> & allowedAttrs() const override;
@ -33,7 +48,7 @@ struct ShortUrlInputScheme : nix::fetchers::InputScheme
getAccessor(const nix::fetchers::Settings & settings, Store & store, const nix::fetchers::Input & input) const override;
bool isLocked(const nix::fetchers::Settings & settings, const nix::fetchers::Input & input) const override;
#endif
};
} // namespace nix::shorturl