From 7fbcc8744d68f74a7439957fbc1d7eb8668c024d Mon Sep 17 00:00:00 2001 From: atagen Date: Thu, 23 Apr 2026 22:28:42 +1000 Subject: [PATCH] split <2.34 code in meson --- meson.build | 7 ++++++ src/shorturl-scheme.cc | 55 ++++++++++++++++++++++++++++++++++++++++++ src/shorturl-scheme.hh | 17 ++++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 97ad2e4..b70e186 100644 --- a/meson.build +++ b/meson.build @@ -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', diff --git a/src/shorturl-scheme.cc b/src/shorturl-scheme.cc index 520351c..88c77a8 100644 --- a/src/shorturl-scheme.cc +++ b/src/shorturl-scheme.cc @@ -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::fetchers::Input> +ShortUrlInputScheme::getAccessor(nix::ref 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 +ShortUrlInputScheme::getFingerprint(nix::ref 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 diff --git a/src/shorturl-scheme.hh b/src/shorturl-scheme.hh index 0ec9cf3..874f9e5 100644 --- a/src/shorturl-scheme.hh +++ b/src/shorturl-scheme.hh @@ -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::fetchers::Input> + getAccessor(nix::ref store, const nix::fetchers::Input & input) const override; + + bool isLocked(const nix::fetchers::Input & input) const override; + + std::optional + getFingerprint(nix::ref 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 & 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