Skip to content

Commit

Permalink
feat: support managing submodules via inputs.self
Browse files Browse the repository at this point in the history
Provides sepcial handling for inputs.self. If submodule is set to true,
will re-call getFlake as if the original reference was set. The intended
behavior is for CLI management of the paramenter overriddes any
direct flake.nix settings.
  • Loading branch information
tomberek committed Feb 19, 2023
1 parent a88ae62 commit 3636d49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
auto sUrl = state.symbols.create("url");
auto sFlake = state.symbols.create("flake");
auto sFollows = state.symbols.create("follows");
auto sSubmodules = state.symbols.create("submodules");

fetchers::Attrs attrs;
std::optional<std::string> url;
Expand All @@ -117,6 +118,9 @@ static FlakeInput parseFlakeInput(EvalState & state,
} else if (attr.name == sFlake) {
expectType(state, nBool, *attr.value, attr.pos);
input.isFlake = attr.value->boolean;
} else if (attr.name == sSubmodules) {
expectType(state, nBool, *attr.value, attr.pos);
input.hasSubmodules = attr.value->boolean;
} else if (attr.name == sInputs) {
input.overrides = parseFlakeInputs(state, attr.value, attr.pos, baseDir, lockRootPath);
} else if (attr.name == sFollows) {
Expand Down Expand Up @@ -229,8 +233,17 @@ static Flake getFlake(

auto sInputs = state.symbols.create("inputs");

if (auto inputs = vInfo.attrs->get(sInputs))
if (auto inputs = vInfo.attrs->get(sInputs)){
flake.inputs = parseFlakeInputs(state, inputs->value, inputs->pos, flakeDir, lockRootPath);
if (originalRef.input.attrs.count("submodules") == 0) {
if (auto self = flake.inputs.find("self") ; self != flake.inputs.end() && self->second.hasSubmodules) {
auto newRef = originalRef;
newRef.input.attrs["submodules"] = nix::Explicit<bool>{true};
warn("Using Git submodules due to input.self.submodule value");
return getFlake(state,newRef,allowLookup,flakeCache,lockRootPath);
}
}
}

auto sOutputs = state.symbols.create("outputs");

Expand Down Expand Up @@ -405,6 +418,7 @@ LockedFlake lockFlake(
necessary (i.e. if they're new or the flakeref changed
from what's in the lock file). */
for (auto & [id, input2] : flakeInputs) {
if (id == "self") continue;
auto inputPath(inputPathPrefix);
inputPath.push_back(id);
auto inputPathS = printInputPath(inputPath);
Expand Down
1 change: 1 addition & 0 deletions src/libexpr/flake/flake.hh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef std::map<FlakeId, FlakeInput> FlakeInputs;
struct FlakeInput
{
std::optional<FlakeRef> ref;
bool hasSubmodules = false;
bool isFlake = true; // true = process flake to get outputs, false = (fetched) static source path
std::optional<InputPath> follows;
FlakeInputs overrides;
Expand Down

0 comments on commit 3636d49

Please sign in to comment.