exporter -> bundler

This commit is contained in:
Matthew Bauer 2020-07-30 15:03:57 -05:00
parent 5d04a4db9b
commit 52407f83a1
2 changed files with 28 additions and 28 deletions

View file

@ -6,18 +6,18 @@
using namespace nix; using namespace nix;
struct CmdExport : InstallableCommand struct CmdBundle : InstallableCommand
{ {
std::string exporter = "github:matthewbauer/nix-bundle"; std::string bundler = "github:matthewbauer/nix-bundle";
Path outLink; Path outLink;
CmdExport() CmdBundle()
{ {
addFlag({ addFlag({
.longName = "exporter", .longName = "bundler",
.description = "use custom exporter", .description = "use custom bundler",
.labels = {"flake-url"}, .labels = {"flake-url"},
.handler = {&exporter}, .handler = {&bundler},
.completer = {[&](size_t, std::string_view prefix) { .completer = {[&](size_t, std::string_view prefix) {
completeFlakeRef(getStore(), prefix); completeFlakeRef(getStore(), prefix);
}} }}
@ -35,15 +35,15 @@ struct CmdExport : InstallableCommand
std::string description() override std::string description() override
{ {
return "export an application out of the Nix store"; return "bundle an application so that it works outside of the Nix store";
} }
Examples examples() override Examples examples() override
{ {
return { return {
Example{ Example{
"To export Hello:", "To bundle Hello:",
"nix export hello" "nix bundle hello"
}, },
}; };
} }
@ -71,12 +71,12 @@ struct CmdExport : InstallableCommand
auto app = installable->toApp(*evalState); auto app = installable->toApp(*evalState);
store->buildPaths(app.context); store->buildPaths(app.context);
auto [exporterFlakeRef, exporterName] = parseFlakeRefWithFragment(exporter, absPath(".")); auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath("."));
const flake::LockFlags lockFlags{ .writeLockFile = false }; const flake::LockFlags lockFlags{ .writeLockFile = false };
auto exporter = InstallableFlake( auto bundler = InstallableFlake(
evalState, std::move(exporterFlakeRef), evalState, std::move(bundlerFlakeRef),
Strings{exporterName == "" ? ("defaultExporter." + settings.thisSystem.get()) : exporterName}, Strings{bundlerName == "" ? ("defaultBundler." + settings.thisSystem.get()) : bundlerName},
Strings({"exporters." + settings.thisSystem.get() + "."}), lockFlags); Strings({"bundlers." + settings.thisSystem.get() + "."}), lockFlags);
Value * arg = evalState->allocValue(); Value * arg = evalState->allocValue();
evalState->mkAttrs(*arg, 1); evalState->mkAttrs(*arg, 1);
@ -87,21 +87,21 @@ struct CmdExport : InstallableCommand
mkString(*evalState->allocAttr(*arg, evalState->symbols.create("program")), app.program, context); mkString(*evalState->allocAttr(*arg, evalState->symbols.create("program")), app.program, context);
auto vRes = evalState->allocValue(); auto vRes = evalState->allocValue();
evalState->callFunction(*exporter.toValue(*evalState).first, *arg, *vRes, noPos); evalState->callFunction(*bundler.toValue(*evalState).first, *arg, *vRes, noPos);
if (!evalState->isDerivation(*vRes)) if (!evalState->isDerivation(*vRes))
throw Error("the exporter '%s' does not produce a derivation", exporter.what()); throw Error("the bundler '%s' does not produce a derivation", bundler.what());
Bindings::iterator i = vRes->attrs->find(evalState->sDrvPath); Bindings::iterator i = vRes->attrs->find(evalState->sDrvPath);
if (i == vRes->attrs->end()) if (i == vRes->attrs->end())
throw Error("the exporter '%s' does not produce a derivation", exporter.what()); throw Error("the bundler '%s' does not produce a bderivation", bundler.what());
PathSet context2; PathSet context2;
StorePath drvPath = store->parseStorePath(evalState->coerceToPath(*i->pos, *i->value, context2)); StorePath drvPath = store->parseStorePath(evalState->coerceToPath(*i->pos, *i->value, context2));
i = vRes->attrs->find(evalState->sOutPath); i = vRes->attrs->find(evalState->sOutPath);
if (i == vRes->attrs->end()) if (i == vRes->attrs->end())
throw Error("the exporter '%s' does not produce a derivation", exporter.what()); throw Error("the bundler '%s' does not produce a derivation", bundler.what());
StorePath outPath = store->parseStorePath(evalState->coerceToPath(*i->pos, *i->value, context2)); StorePath outPath = store->parseStorePath(evalState->coerceToPath(*i->pos, *i->value, context2));
@ -110,11 +110,11 @@ struct CmdExport : InstallableCommand
auto accessor = store->getFSAccessor(); auto accessor = store->getFSAccessor();
auto outPathS = store->printStorePath(outPath); auto outPathS = store->printStorePath(outPath);
if (accessor->stat(outPathS).type != FSAccessor::tRegular) if (accessor->stat(outPathS).type != FSAccessor::tRegular)
throw Error("'%s' is not a file; an exporter must only create a single file", outPathS); throw Error("'%s' is not a file; a bundler must only create a single file", outPathS);
auto info = store->queryPathInfo(outPath); auto info = store->queryPathInfo(outPath);
if (!info->references.empty()) if (!info->references.empty())
throw Error("'%s' has references; an exporter must not leave any references", outPathS); throw Error("'%s' has references; a bundler must not leave any references", outPathS);
if (outLink == "") if (outLink == "")
outLink = baseNameOf(app.program); outLink = baseNameOf(app.program);
@ -123,4 +123,4 @@ struct CmdExport : InstallableCommand
} }
}; };
static auto r2 = registerCommand<CmdExport>("export"); static auto r2 = registerCommand<CmdBundle>("bundle");

View file

@ -368,14 +368,14 @@ struct CmdFlakeCheck : FlakeCommand
} }
}; };
auto checkExporter = [&](const std::string & attrPath, Value & v, const Pos & pos) { auto checkBundler = [&](const std::string & attrPath, Value & v, const Pos & pos) {
try { try {
state->forceValue(v, pos); state->forceValue(v, pos);
if (v.type != tLambda) if (v.type != tLambda)
throw Error("exporter must be a function"); throw Error("bundler must be a function");
if (!v.lambda.fun->formals || if (!v.lambda.fun->formals ||
v.lambda.fun->formals->argNames.find(state->symbols.create("program")) == v.lambda.fun->formals->argNames.end()) v.lambda.fun->formals->argNames.find(state->symbols.create("program")) == v.lambda.fun->formals->argNames.end())
throw Error("exporter must take formal argument 'program'"); throw Error("bundler must take formal argument 'program'");
} catch (Error & e) { } catch (Error & e) {
e.addTrace(pos, hintfmt("while checking the template '%s'", attrPath)); e.addTrace(pos, hintfmt("while checking the template '%s'", attrPath));
throw; throw;
@ -504,19 +504,19 @@ struct CmdFlakeCheck : FlakeCommand
*attr.value, *attr.pos); *attr.value, *attr.pos);
} }
else if (name == "defaultExporter") else if (name == "defaultBundler")
for (auto & attr : *vOutput.attrs) { for (auto & attr : *vOutput.attrs) {
checkSystemName(attr.name, *attr.pos); checkSystemName(attr.name, *attr.pos);
checkExporter(fmt("%s.%s", name, attr.name), *attr.value, *attr.pos); checkBundler(fmt("%s.%s", name, attr.name), *attr.value, *attr.pos);
} }
else if (name == "exporters") { else if (name == "bundlers") {
state->forceAttrs(vOutput, pos); state->forceAttrs(vOutput, pos);
for (auto & attr : *vOutput.attrs) { for (auto & attr : *vOutput.attrs) {
checkSystemName(attr.name, *attr.pos); checkSystemName(attr.name, *attr.pos);
state->forceAttrs(*attr.value, *attr.pos); state->forceAttrs(*attr.value, *attr.pos);
for (auto & attr2 : *attr.value->attrs) for (auto & attr2 : *attr.value->attrs)
checkExporter( checkBundler(
fmt("%s.%s.%s", name, attr.name, attr2.name), fmt("%s.%s.%s", name, attr.name, attr2.name),
*attr2.value, *attr2.pos); *attr2.value, *attr2.pos);
} }