mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-08 19:27:18 +02:00
Merge branch 'pr/mopleen/5625'
This commit is contained in:
commit
351e70ea68
4 changed files with 74 additions and 10 deletions
|
@ -559,18 +559,39 @@ InstallableFlake::InstallableFlake(
|
||||||
throw UsageError("'--arg' and '--argstr' are incompatible with flakes");
|
throw UsageError("'--arg' and '--argstr' are incompatible with flakes");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
namespace {
|
||||||
{
|
std::optional<Path> getSourceFilePathFromInStorePath(Store & store, const Path & file, const fetchers::Input & flakeInput) {
|
||||||
auto lockedFlake = getLockedFlake();
|
if (!store.isInStore(file)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
auto cache = openEvalCache(*state, lockedFlake);
|
auto [sourceStorePath, relPath] = store.toStorePath(file);
|
||||||
|
auto realPath = store.toRealPath(sourceStorePath);
|
||||||
|
|
||||||
|
auto maybeFlakeSource = flakeInput.getSourcePath();
|
||||||
|
if (!maybeFlakeSource) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto betterFilePath = replaceStrings(file, realPath, *maybeFlakeSource);
|
||||||
|
if (!pathExists(betterFilePath)) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return betterFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> toDerivationImpl(InstallableFlake & flake) {
|
||||||
|
auto lockedFlake = flake.getLockedFlake();
|
||||||
|
|
||||||
|
auto cache = openEvalCache(*flake.state, lockedFlake);
|
||||||
auto root = cache->getRoot();
|
auto root = cache->getRoot();
|
||||||
|
|
||||||
for (auto & attrPath : getActualAttrPaths()) {
|
for (auto & attrPath : flake.getActualAttrPaths()) {
|
||||||
debug("trying flake output attribute '%s'", attrPath);
|
debug("trying flake output attribute '%s'", attrPath);
|
||||||
|
|
||||||
auto attr = root->findAlongAttrPath(
|
auto attr = root->findAlongAttrPath(
|
||||||
parseAttrPath(*state, attrPath),
|
parseAttrPath(*flake.state, attrPath),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -581,17 +602,39 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
|
||||||
|
|
||||||
auto drvPath = attr->forceDerivation();
|
auto drvPath = attr->forceDerivation();
|
||||||
|
|
||||||
auto drvInfo = DerivationInfo{
|
auto drvInfo = InstallableValue::DerivationInfo{
|
||||||
std::move(drvPath),
|
std::move(drvPath),
|
||||||
state->store->maybeParseStorePath(attr->getAttr(state->sOutPath)->getString()),
|
flake.state->store->maybeParseStorePath(attr->getAttr(flake.state->sOutPath)->getString()),
|
||||||
attr->getAttr(state->sOutputName)->getString()
|
attr->getAttr(flake.state->sOutputName)->getString()
|
||||||
};
|
};
|
||||||
|
|
||||||
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)};
|
return {attrPath, lockedFlake->flake.lockedRef, std::move(drvInfo)};
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Error("flake '%s' does not provide attribute %s",
|
throw Error("flake '%s' does not provide attribute %s",
|
||||||
flakeRef, showAttrPaths(getActualAttrPaths()));
|
flake.flakeRef, showAttrPaths(flake.getActualAttrPaths()));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class F>
|
||||||
|
auto patchErrorSourceFile(Store & store, const fetchers::Input & flakeInput, F && func) {
|
||||||
|
try {
|
||||||
|
return func();
|
||||||
|
} catch (BaseError & e) {
|
||||||
|
if (auto pos = e.info().errPos) {
|
||||||
|
if (auto sourceFilePath = getSourceFilePathFromInStorePath(store, pos->file, flakeInput)) {
|
||||||
|
e.replacePosFile(*sourceFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
||||||
|
{
|
||||||
|
return patchErrorSourceFile(*state->store, flakeRef.input, [&] {
|
||||||
|
return toDerivationImpl(*this);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
||||||
|
|
|
@ -164,6 +164,12 @@ public:
|
||||||
|
|
||||||
const string & msg() const { return calcWhat(); }
|
const string & msg() const { return calcWhat(); }
|
||||||
const ErrorInfo & info() const { calcWhat(); return err; }
|
const ErrorInfo & info() const { calcWhat(); return err; }
|
||||||
|
|
||||||
|
void replacePosFile(std::string file) {
|
||||||
|
if (err.errPos) {
|
||||||
|
err.errPos->file = std::move(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
BaseError & addTrace(std::optional<ErrPos> e, const string &fs, const Args & ... args)
|
BaseError & addTrace(std::optional<ErrPos> e, const string &fs, const Args & ... args)
|
||||||
|
|
14
tests/flake-print-local-path-error.sh
Normal file
14
tests/flake-print-local-path-error.sh
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
clearStore
|
||||||
|
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
||||||
|
|
||||||
|
cd $TEST_HOME
|
||||||
|
|
||||||
|
cat <<EOF > flake.nix
|
||||||
|
{
|
||||||
|
outputs = give me an error here;
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
nix build |& grep $TEST_HOME || fail "Path should point to home, not to the store"
|
|
@ -49,6 +49,7 @@ nix_tests = \
|
||||||
flake-local-settings.sh \
|
flake-local-settings.sh \
|
||||||
flake-searching.sh \
|
flake-searching.sh \
|
||||||
flake-bundler.sh \
|
flake-bundler.sh \
|
||||||
|
flake-print-local-path-error.sh \
|
||||||
build.sh \
|
build.sh \
|
||||||
repl.sh ca/repl.sh \
|
repl.sh ca/repl.sh \
|
||||||
ca/build.sh \
|
ca/build.sh \
|
||||||
|
|
Loading…
Add table
Reference in a new issue