Merge pull request #6100 from edolstra/installables-cleanup

InstallableFlake: Default attr paths cleanup
This commit is contained in:
Eelco Dolstra 2022-02-14 22:06:11 +01:00 committed by GitHub
commit 94992a9196
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 27 deletions

View file

@ -545,13 +545,14 @@ InstallableFlake::InstallableFlake(
SourceExprCommand * cmd,
ref<EvalState> state,
FlakeRef && flakeRef,
Strings && attrPaths,
Strings && prefixes,
std::string_view fragment,
Strings attrPaths,
Strings prefixes,
const flake::LockFlags & lockFlags)
: InstallableValue(state),
flakeRef(flakeRef),
attrPaths(attrPaths),
prefixes(prefixes),
attrPaths(fragment == "" ? attrPaths : Strings{(std::string) fragment}),
prefixes(fragment == "" ? Strings{} : prefixes),
lockFlags(lockFlags)
{
if (cmd && cmd->getAutoArgs(*state)->size())
@ -566,6 +567,8 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
auto root = cache->getRoot();
for (auto & attrPath : getActualAttrPaths()) {
debug("trying flake output attribute '%s'", attrPath);
auto attr = root->findAlongAttrPath(
parseAttrPath(*state, attrPath),
true
@ -708,8 +711,9 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
this,
getEvalState(),
std::move(flakeRef),
fragment == "" ? getDefaultFlakeAttrPaths() : Strings{fragment},
fragment == "" ? Strings{} : getDefaultFlakeAttrPathPrefixes(),
fragment,
getDefaultFlakeAttrPaths(),
getDefaultFlakeAttrPathPrefixes(),
lockFlags));
continue;
} catch (...) {

View file

@ -102,8 +102,9 @@ struct InstallableFlake : InstallableValue
SourceExprCommand * cmd,
ref<EvalState> state,
FlakeRef && flakeRef,
Strings && attrPaths,
Strings && prefixes,
std::string_view fragment,
Strings attrPaths,
Strings prefixes,
const flake::LockFlags & lockFlags);
std::string what() const override { return flakeRef.to_string() + "#" + *attrPaths.begin(); }

View file

@ -74,21 +74,16 @@ struct CmdBundle : InstallableCommand
{
auto evalState = getEvalState();
auto [progFlakeRef, progName] = parseFlakeRefWithFragment(installable->what(), absPath("."));
const flake::LockFlags lockFlagsProg{ .writeLockFile = false };
auto programInstallable = InstallableFlake(this,
evalState, std::move(progFlakeRef),
Strings{progName == "" ? "defaultApp" : progName},
Strings(this->getDefaultFlakeAttrPathPrefixes()),
lockFlagsProg);
auto val = programInstallable.toValue(*evalState).first;
auto val = installable->toValue(*evalState).first;
auto [bundlerFlakeRef, bundlerName] = parseFlakeRefWithFragment(bundler, absPath("."));
const flake::LockFlags lockFlags{ .writeLockFile = false };
auto bundler = InstallableFlake(this,
evalState, std::move(bundlerFlakeRef),
Strings{bundlerName == "" ? "defaultBundler." + settings.thisSystem.get() : settings.thisSystem.get() + "." + bundlerName, bundlerName},
Strings({"","bundlers."}), lockFlags);
InstallableFlake bundler{this,
evalState, std::move(bundlerFlakeRef), bundlerName,
{"defaultBundler." + settings.thisSystem.get()},
{"bundlers." + settings.thisSystem.get() + "."},
lockFlags
};
auto vRes = evalState->allocValue();
evalState->callFunction(*bundler.toValue(*evalState).first, *val, *vRes, noPos);

View file

@ -498,7 +498,8 @@ struct CmdDevelop : Common, MixEnvironment
this,
state,
installable->nixpkgsFlakeRef(),
Strings{"bashInteractive"},
"bashInteractive",
Strings{},
Strings{"legacyPackages." + settings.thisSystem.get() + "."},
nixpkgsLockFlags);

View file

@ -649,12 +649,14 @@ struct CmdFlakeCheck : FlakeCommand
}
};
static Strings defaultTemplateAttrPathsPrefixes{"templates."};
static Strings defaultTemplateAttrPaths = {"defaultTemplate"};
struct CmdFlakeInitCommon : virtual Args, EvalCommand
{
std::string templateUrl = "templates";
Path destDir;
const Strings attrsPathPrefixes{"templates."};
const LockFlags lockFlags{ .writeLockFile = false };
CmdFlakeInitCommon()
@ -669,8 +671,8 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
completeFlakeRefWithFragment(
getEvalState(),
lockFlags,
attrsPathPrefixes,
{"defaultTemplate"},
defaultTemplateAttrPathsPrefixes,
defaultTemplateAttrPaths,
prefix);
}}
});
@ -685,9 +687,10 @@ struct CmdFlakeInitCommon : virtual Args, EvalCommand
auto [templateFlakeRef, templateName] = parseFlakeRefWithFragment(templateUrl, absPath("."));
auto installable = InstallableFlake(nullptr,
evalState, std::move(templateFlakeRef),
Strings{templateName == "" ? "defaultTemplate" : templateName},
Strings(attrsPathPrefixes), lockFlags);
evalState, std::move(templateFlakeRef), templateName,
defaultTemplateAttrPaths,
defaultTemplateAttrPathsPrefixes,
lockFlags);
auto [cursor, attrPath] = installable.getCursor(*evalState);

View file

@ -423,6 +423,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
this,
getEvalState(),
FlakeRef(element.source->originalRef),
"",
{element.source->attrPath},
{},
lockFlags);