Fix build for Nix 2.19 to 2.21

dblsaiko
Mar 19, 2024, 9:32 PM
U5AKEHEQWHBOVXMTTQFBJA4M4VJ7OWSJJVYYB6FLTJB7NCFPYVRQC

Dependencies

  • [2] 3KEFKH5F Import existing code
  • [3] 7YS2X7JJ Fix compilation against older Nix versions (tested with 2.13.6)

Change contents

  • edit in src/fetcher.cpp at line 7
    [2.169]
    [2.169]
    #if NIX_VERSION >= 0x021900
    #include <processes.hh>
    #endif
  • edit in src/fetcher.cpp at line 12
    [2.170]
    [2.170]
    #if NIX_VERSION >= 0x022000
    #include <posix-source-accessor.hh>
    #endif
    #if NIX_VERSION >= 0x022100
    #include <fs-input-accessor.hh>
    #endif
  • edit in src/fetcher.cpp at line 88
    [2.1933]
    [2.1933]
    #if NIX_VERSION < 0x021900
  • edit in src/fetcher.cpp at line 94
    [2.2231]
    [2.2231]
    #endif
  • edit in src/fetcher.cpp at line 101
    [2.2328]
    [2.2328]
    #if NIX_VERSION < 0x022100
  • edit in src/fetcher.cpp at line 105
    [2.2467]
    [2.2467]
    #endif
  • edit in src/fetcher.cpp at line 110
    [2.2497]
    [2.2497]
    #if NIX_VERSION < 0x021900
  • edit in src/fetcher.cpp at line 115
    [2.2651]
    [2.2651]
    #endif
  • edit in src/fetcher.cpp at line 136
    [2.3215]
    [2.3215]
    #if NIX_VERSION >= 0x022100
    std::pair<StorePath, Input> fetchToStore(ref<Store> store, const Input &_input) const
    #else
  • edit in src/fetcher.cpp at line 140
    [2.3301]
    [2.3301]
    #endif
  • edit in src/fetcher.cpp at line 153
    [2.3662]
    [2.3662]
    #if NIX_VERSION >= 0x021900
    std::optional<Path> getSourcePath(const Input &input) const override
    #else
  • edit in src/fetcher.cpp at line 157
    [2.3729]
    [2.3729]
    #endif
  • edit in src/fetcher.cpp at line 167
    [2.3936]
    [2.3936]
    #if NIX_VERSION >= 0x021900
    void putFile(const Input &input, const CanonPath &path, std::string_view contents, std::optional<std::string> commitMsg) const override
    {
    auto root = getSourcePath(input);
    assert(root);
    #if NIX_VERSION >= 0x022100
    writeFile((CanonPath(*root) / path).abs(), contents);
    #else
    writeFile((CanonPath(*root) + path).abs(), contents);
    #endif
    runPijul({"add", "--", std::string(path.rel())}, root);
  • edit in src/fetcher.cpp at line 182
    [2.3937]
    [2.3937]
    if (commitMsg)
    runPijul({"record", std::string(path.rel()), "-m", *commitMsg}, root, {}, true);
    }
    #else
  • replacement in src/fetcher.cpp at line 188
    [2.4058][2.4058:4134]()
    auto sourcePath = getSourcePath(input);
    assert(sourcePath);
    [2.4058]
    [2.4134]
    auto root = getSourcePath(input);
    assert(root);
  • replacement in src/fetcher.cpp at line 191
    [2.4135][2.4135:4199]()
    runPijul({"add", "--", std::string(file)}, sourcePath);
    [2.4135]
    [2.4199]
    runPijul({"add", "--", std::string(file)}, root);
  • replacement in src/fetcher.cpp at line 194
    [2.4223][2.4223:4316]()
    runPijul({"record", std::string(file), "-m", *commitMsg}, sourcePath, {}, true);
    [2.4223]
    [2.4316]
    runPijul({"record", std::string(file), "-m", *commitMsg}, root, {}, true);
    }
    #endif
    #if NIX_VERSION >= 0x021900
    std::string_view schemeName() const override
    {
    return "pijul"sv;
    }
    StringSet allowedAttrs() const override
    {
    return {"url"s, "channel"s, "state"s, "narHash"s, "lastModified"s};
    }
    #endif
    #if NIX_VERSION >= 0x022100
    bool isLocked(const Input &input) const override
    {
    return maybeGetStrAttr(input.attrs, "channel") && maybeGetStrAttr(input.attrs, "state");
    }
    std::pair<ref<InputAccessor>, Input> getAccessor(ref<Store> store, const Input &_input) const override
    {
    Input input(_input);
    auto [storePath, _] = fetchToStore(store, input);
    return {makeStorePathAccessor(store, storePath), input};
  • edit in src/fetcher.cpp at line 224
    [2.4322]
    [2.4322]
    #endif
  • replacement in src/fetcher.cpp at line 233
    [2.4451][2.4451:4543]()
    static std::pair<StorePath, Attrs> doFetch(const ref<Store> &store, const Input &input)
    [2.4451]
    [2.4543]
    static std::pair<StorePath, Attrs> doFetch(const ref<Store> &_store, const Input &input)
  • edit in src/fetcher.cpp at line 235
    [2.4549]
    [2.4549]
    #if NIX_VERSION >= 0x022000
    Store &store = *_store;
    #else
    const auto &store = _store;
    #endif
  • replacement in src/fetcher.cpp at line 281
    [2.5825][2.5825:5903]()
    auto [storePath, rs] = doFetch(store, name, repoUrl, channel, state);
    [2.5825]
    [2.5903]
    auto [storePath, rs] = doFetch(_store, name, repoUrl, channel, state);
  • edit in src/fetcher.cpp at line 350
    [2.7976]
    [2.7976]
    #if NIX_VERSION >= 0x022100
    auto [accessor, canonPath] = PosixSourceAccessor::createAtRoot(repoDir);
    auto storePath = store->addToStore(inputName, accessor, canonPath);
    #elif NIX_VERSION >= 0x022000
    PosixSourceAccessor accessor;
    auto storePath = store->addToStore(inputName, accessor, CanonPath::fromCwd(repoDir));
    #else
  • edit in src/fetcher.cpp at line 358
    [2.8040]
    [2.8040]
    #endif
  • edit in src/fetcher.cpp at line 413
    [2.9697]
    [2.9697]
    #if NIX_VERSION >= 0x022000
    PosixSourceAccessor accessor;
    auto storePath = store->addToStore(input.getName(), accessor, CanonPath{actualPath}, FileIngestionMethod::Recursive, HashAlgorithm::SHA256, {}, filter);
    #else
  • edit in src/fetcher.cpp at line 418
    [2.9820]
    [2.9820]
    #endif