1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/// @file WASM stubs for Store default methods defined in build/entry-points.cc,
/// fetcher functions from libfetchers, and archive functions from libutil/archive.cc.
/// These are all unreachable in the WASM evaluator (no building, no network fetching),
/// but the linker requires the symbols to exist.

#include "lix/libstore/build-result.hh"
#include "lix/libstore/store-api.hh"
#include "lix/libutil/error.hh"
#include "lix/libutil/result.hh"
#include "lix/libutil/archive.hh"
#include "lix/libfetchers/fetchers.hh"
#include "lix/libfetchers/fetch-to-store.hh"
#include "lix/libfetchers/registry.hh"
#include "lix/libfetchers/attrs.hh"
#include "lix/libfetchers/fetch-settings.hh"
#include "lix/libutil/url.hh"
#include "lix/libutil/json.hh"
#include "lix/libutil/file-system.hh"
#include "lix/libutil/canon-path.hh"
#include "lix/libutil/processes.hh"

#include <kj/async.h>

namespace nix {

// ---------------------------------------------------------------------------
// Store default method impls (from build/entry-points.cc, excluded in WASM)
// ---------------------------------------------------------------------------

kj::Promise<Result<void>>
Store::buildPaths(const std::vector<DerivedPath> &, BuildMode, std::shared_ptr<Store>)
try {
    throw Error("Store::buildPaths not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

kj::Promise<Result<std::vector<KeyedBuildResult>>>
Store::buildPathsWithResults(const std::vector<DerivedPath> &, BuildMode, std::shared_ptr<Store>)
try {
    throw Error("Store::buildPathsWithResults not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

kj::Promise<Result<BuildResult>> Store::buildDerivation(const StorePath &, const BasicDerivation &, BuildMode)
try {
    throw Error("Store::buildDerivation not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

kj::Promise<Result<void>> Store::ensurePath(const StorePath &)
try {
    throw Error("Store::ensurePath not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// ---------------------------------------------------------------------------
// archive.cc stubs (archive.cc excluded from WASM build)
// ---------------------------------------------------------------------------

box_ptr<PreparedDump> prepareDump(Path)
{
    throw Error("prepareDump not available in WASM evaluator");
}

box_ptr<PreparedDump> prepareDump(Path, PathFilter &)
{
    throw Error("prepareDump not available in WASM evaluator");
}

kj::Promise<Result<StorePath>>
fetchToStoreRecursive(Store &, const PreparedDump &, std::string_view, RepairFlag)
try {
    throw Error("fetchToStoreRecursive not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// ---------------------------------------------------------------------------
// fetchers stubs (libfetchers excluded from WASM build)
// ---------------------------------------------------------------------------

namespace fetchers {

void initLibFetchers() {} // no-op — no fetcher backends in WASM

kj::Promise<Result<DownloadTarballResult>>
downloadTarball(ref<Store>, const std::string &, const std::string &, bool, const Headers &)
try {
    throw Error("downloadTarball not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// Input method stubs
std::string Input::toURLString(const std::map<std::string, std::string> &) const
{
    throw Error("Input::toURLString not available in WASM evaluator");
}

Attrs Input::toAttrs() const
{
    throw Error("Input::toAttrs not available in WASM evaluator");
}

bool Input::operator==(const Input &) const
{
    return false;
}

kj::Promise<Result<std::pair<Tree, Input>>> Input::fetch(ref<Store>) const
try {
    throw Error("Input::fetch not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

kj::Promise<Result<std::pair<Input, Attrs>>> lookupInRegistries(ref<Store>, const Input &)
try {
    throw Error("lookupInRegistries not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// maybeGetStrAttr provided by libfetchers/attrs.cc

// Additional Input method stubs
std::optional<Path> Input::getSourcePath() const
{
    return std::nullopt;
}
std::string Input::getType() const
{
    return "";
}
std::optional<std::string> Input::getRef() const
{
    return std::nullopt;
}
std::optional<Hash> Input::getRev() const
{
    return std::nullopt;
}
StorePath Input::computeStorePath(Store &) const
{
    throw Error("Input::computeStorePath not available in WASM evaluator");
}
std::optional<Hash> Input::getNarHash() const
{
    return std::nullopt;
}
std::optional<time_t> Input::getLastModified() const
{
    return std::nullopt;
}

Input Input::fromURL(const ParsedURL &, bool)
{
    throw Error("Input::fromURL not available in WASM evaluator");
}

Input Input::fromURL(const std::string &, bool)
{
    throw Error("Input::fromURL not available in WASM evaluator");
}

Input Input::fromAttrs(Attrs &&)
{
    throw Error("Input::fromAttrs not available in WASM evaluator");
}

kj::Promise<Result<void>>
Input::putFile(const CanonPath &, std::string_view, std::optional<std::string>) const
try {
    throw Error("Input::putFile not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// Attrs serialization is provided by libfetchers/attrs.cc

// Additional Input method stubs (continued)
std::optional<uint64_t> Input::getRevCount() const
{
    return std::nullopt;
}

// downloadFile — from tarball.cc
kj::Promise<Result<DownloadFileResult>>
downloadFile(ref<Store>, const std::string &, const std::string &, bool, Headers, FileIngestionMethod)
try {
    throw Error("downloadFile not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

} // namespace fetchers

// ---------------------------------------------------------------------------
// archive.cc additional stubs
// ---------------------------------------------------------------------------

// defaultPathFilter — defined in archive.cc (excluded from WASM)
PathFilter defaultPathFilter = [](const Path &) { return true; };

// fetchToStoreFlat — from fetch-to-store.cc
kj::Promise<Result<StorePath>>
fetchToStoreFlat(Store &, const CheckedSourcePath &, std::string_view, RepairFlag)
try {
    throw Error("fetchToStoreFlat not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// runProgram — from processes.cc (excluded from WASM)
kj::Promise<Result<std::string>> runProgram(Path, bool, const Strings, bool)
try {
    throw Error("runProgram not available in WASM evaluator");
} catch (...) {
    return {result::current_exception()};
}

// fetchSettings and FetchSettings constructor come from fetch-settings.cc
// which is now included in the WASM build via meson.

} // namespace nix