Refactor bundler API
Bundlers now expect to be located at bundlers.<system>.<name> and are a function from derivations to derivations.
This commit is contained in:
parent
3be810f5db
commit
c94db0535c
|
@ -69,39 +69,24 @@ struct CmdBundle : InstallableCommand
|
||||||
{
|
{
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
|
|
||||||
auto app = installable->toApp(*evalState).resolve(getEvalStore(), store);
|
|
||||||
|
|
||||||
auto [progFlakeRef, progName] = parseFlakeRefWithFragment(installable->what(), absPath("."));
|
auto [progFlakeRef, progName] = parseFlakeRefWithFragment(installable->what(), absPath("."));
|
||||||
const flake::LockFlags lockFlagsProg{ .writeLockFile = false };
|
const flake::LockFlags lockFlagsProg{ .writeLockFile = false };
|
||||||
auto programInstallable = InstallableFlake(this,
|
auto programInstallable = InstallableFlake(this,
|
||||||
evalState, std::move(progFlakeRef),
|
evalState, std::move(progFlakeRef),
|
||||||
Strings{progName == "" ? "defaultPackage" : progName},
|
Strings{progName == "" ? "defaultApp" : progName},
|
||||||
Strings({"packages."+settings.thisSystem.get()+".","legacyPackages."+settings.thisSystem.get()+"."}), lockFlagsProg);
|
Strings(this->getDefaultFlakeAttrPathPrefixes()),
|
||||||
|
lockFlagsProg);
|
||||||
auto val = programInstallable.toValue(*evalState).first;
|
auto val = programInstallable.toValue(*evalState).first;
|
||||||
|
|
||||||
auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath("."));
|
auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath("."));
|
||||||
const flake::LockFlags lockFlags{ .writeLockFile = false };
|
const flake::LockFlags lockFlags{ .writeLockFile = false };
|
||||||
auto bundler = InstallableFlake(this,
|
auto bundler = InstallableFlake(this,
|
||||||
evalState, std::move(bundlerFlakeRef),
|
evalState, std::move(bundlerFlakeRef),
|
||||||
Strings{bundlerName == "" ? "defaultBundler" : bundlerName},
|
Strings{bundlerName == "" ? "defaultBundler." + settings.thisSystem.get() : settings.thisSystem.get() + "." + bundlerName},
|
||||||
Strings({"bundlers."}), lockFlags);
|
Strings({"bundlers."}), lockFlags);
|
||||||
|
|
||||||
auto attrs = evalState->buildBindings(2);
|
|
||||||
|
|
||||||
Value & prog = *evalState->allocAttr(*arg, evalState->symbols.create("program"));
|
|
||||||
evalState->mkAttrs(prog,val->attrs->size());
|
|
||||||
for (auto &j : *(val->attrs)){
|
|
||||||
prog.attrs->push_back(j);
|
|
||||||
}
|
|
||||||
prog.attrs->sort();
|
|
||||||
|
|
||||||
attrs.alloc("system").mkString(settings.thisSystem.get());
|
|
||||||
|
|
||||||
auto vRes = evalState->allocValue();
|
auto vRes = evalState->allocValue();
|
||||||
evalState->callFunction(
|
evalState->callFunction(*bundler.toValue(*evalState).first, *val, *vRes, noPos);
|
||||||
*bundler.toValue(*evalState).first,
|
|
||||||
evalState->allocValue()->mkAttrs(attrs),
|
|
||||||
*vRes, noPos);
|
|
||||||
|
|
||||||
if (!evalState->isDerivation(*vRes))
|
if (!evalState->isDerivation(*vRes))
|
||||||
throw Error("the bundler '%s' does not produce a derivation", bundler.what());
|
throw Error("the bundler '%s' does not produce a derivation", bundler.what());
|
||||||
|
@ -123,9 +108,12 @@ struct CmdBundle : InstallableCommand
|
||||||
|
|
||||||
auto outPathS = store->printStorePath(outPath);
|
auto outPathS = store->printStorePath(outPath);
|
||||||
|
|
||||||
if (!outLink)
|
if (!outLink) {
|
||||||
outLink = baseNameOf(app.program);
|
auto &attr = vRes->attrs->need(evalState->sName);
|
||||||
|
outLink = evalState->forceStringNoCtx(*attr.value,*attr.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: will crash if not a localFSStore?
|
||||||
store.dynamic_pointer_cast<LocalFSStore>()->addPermRoot(outPath, absPath(*outLink));
|
store.dynamic_pointer_cast<LocalFSStore>()->addPermRoot(outPath, absPath(*outLink));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,12 +18,20 @@ R""(
|
||||||
nix (Nix) 2.4pre20201215_e3ddffb
|
nix (Nix) 2.4pre20201215_e3ddffb
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Bundle a Hello using a specific bundler:
|
||||||
|
|
||||||
|
```console
|
||||||
|
# nix bundle --bundler github:NixOS/bundlers#toDockerImage nixpkgs#hello
|
||||||
|
# docker load < hello-2.10.tar.gz
|
||||||
|
# docker run hello-2.10:latest hello
|
||||||
|
Hello, world!
|
||||||
|
```
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
|
|
||||||
`nix bundle` packs the closure of the [Nix app](./nix3-run.md)
|
`nix bundle`, by default, packs the closure of the [Nix app](./nix3-run.md)
|
||||||
*installable* into a single self-extracting executable. See the
|
*installable* into a single self-extracting executable. See the [`nix-bundle`
|
||||||
[`nix-bundle` homepage](https://github.com/matthewbauer/nix-bundle)
|
homepage](https://github.com/matthewbauer/nix-bundle) for more details.
|
||||||
for more details.
|
|
||||||
|
|
||||||
> **Note**
|
> **Note**
|
||||||
>
|
>
|
||||||
|
@ -31,6 +39,29 @@ for more details.
|
||||||
|
|
||||||
# Bundler definitions
|
# Bundler definitions
|
||||||
|
|
||||||
TODO
|
If no flake output attribute is given, `nix bundle` tries the following
|
||||||
|
flake output attributes:
|
||||||
|
|
||||||
|
* `defaultBundler.<system>`
|
||||||
|
|
||||||
|
If an attribute *name* is given, `nix run` tries the following flake
|
||||||
|
output attributes:
|
||||||
|
|
||||||
|
* `bundler.<system>.<name>`
|
||||||
|
|
||||||
|
# Bundlers
|
||||||
|
|
||||||
|
An bundlers is specified by a flake output attribute named
|
||||||
|
`bundlers.<system>.<name>` or `defaultBundler.<system>`. It looks like this:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
bundlers.x86_64-linux.identity = drv: drv;
|
||||||
|
|
||||||
|
bundlers.x86_64-linux.blender_2_79 = drv: self.packages.x86_64-linux.blender_2_79;
|
||||||
|
|
||||||
|
defaultBundler.x86_64-linux = drv: drv;
|
||||||
|
```
|
||||||
|
|
||||||
|
A bundler must be a function that accepts a derivation and returns a derivation.
|
||||||
|
|
||||||
)""
|
)""
|
||||||
|
|
|
@ -475,10 +475,7 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
state->forceValue(v, pos);
|
state->forceValue(v, pos);
|
||||||
if (!v.isLambda())
|
if (!v.isLambda())
|
||||||
throw Error("bundler must be a function");
|
throw Error("bundler must be a function");
|
||||||
if (!v.lambda.fun->formals ||
|
// TODO: check types of inputs/outputs?
|
||||||
!v.lambda.fun->formals->argNames.count(state->symbols.create("program")) ||
|
|
||||||
!v.lambda.fun->formals->argNames.count(state->symbols.create("system")))
|
|
||||||
throw Error("bundler must take formal arguments 'program' and 'system'");
|
|
||||||
} 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));
|
||||||
reportError(e);
|
reportError(e);
|
||||||
|
@ -609,14 +606,27 @@ struct CmdFlakeCheck : FlakeCommand
|
||||||
*attr.value, *attr.pos);
|
*attr.value, *attr.pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (name == "defaultBundler")
|
else if (name == "defaultBundler") {
|
||||||
checkBundler(name, vOutput, pos);
|
state->forceAttrs(vOutput, pos);
|
||||||
|
for (auto & attr : *vOutput.attrs) {
|
||||||
|
checkSystemName(attr.name, *attr.pos);
|
||||||
|
checkBundler(
|
||||||
|
fmt("%s.%s", name, attr.name),
|
||||||
|
*attr.value, *attr.pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else if (name == "bundlers") {
|
else if (name == "bundlers") {
|
||||||
state->forceAttrs(vOutput, pos);
|
state->forceAttrs(vOutput, pos);
|
||||||
for (auto & attr : *vOutput.attrs)
|
for (auto & attr : *vOutput.attrs) {
|
||||||
checkBundler(fmt("%s.%s", name, attr.name),
|
checkSystemName(attr.name, *attr.pos);
|
||||||
*attr.value, *attr.pos);
|
state->forceAttrs(*attr.value, *attr.pos);
|
||||||
|
for (auto & attr2 : *attr.value->attrs) {
|
||||||
|
checkBundler(
|
||||||
|
fmt("%s.%s.%s", name, attr.name, attr2.name),
|
||||||
|
*attr2.value, *attr2.pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue