1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-30 19:57:59 +02:00

Turn flake inputs into an attrset

Instead of a list, inputs are now an attrset like

  inputs = {
    nixpkgs.uri = github:NixOS/nixpkgs;
  };

If 'uri' is omitted, than the flake is a lookup in the flake registry, e.g.

  inputs = {
    nixpkgs = {};
  };

but in that case, you can also just omit the input altogether and
specify it as an argument to the 'outputs' function, as in

  outputs = { self, nixpkgs }: ...

This also gets rid of 'nonFlakeInputs', which are now just a special
kind of input that have a 'flake = false' attribute, e.g.

  inputs = {
    someRepo = {
      uri = github:example/repo;
      flake = false;
    };
  };
This commit is contained in:
Eelco Dolstra 2019-08-30 16:27:51 +02:00
parent 0588d72286
commit 30ccf4e52d
7 changed files with 136 additions and 220 deletions

View file

@ -3,83 +3,57 @@
namespace nix::flake {
AbstractInput::AbstractInput(const nlohmann::json & json)
: ref(json["uri"])
LockedInput::LockedInput(const nlohmann::json & json)
: LockedInputs(json)
, ref(json["uri"])
, narHash(Hash((std::string) json["narHash"]))
{
if (!ref.isImmutable())
throw Error("lockfile contains mutable flakeref '%s'", ref);
}
nlohmann::json AbstractInput::toJson() const
nlohmann::json LockedInput::toJson() const
{
nlohmann::json json;
auto json = LockedInputs::toJson();
json["uri"] = ref.to_string();
json["narHash"] = narHash.to_string(SRI);
return json;
}
Path AbstractInput::computeStorePath(Store & store) const
Path LockedInput::computeStorePath(Store & store) const
{
return store.makeFixedOutputPath(true, narHash, "source");
}
FlakeInput::FlakeInput(const nlohmann::json & json)
: FlakeInputs(json)
, AbstractInput(json)
, id(json["id"])
LockedInputs::LockedInputs(const nlohmann::json & json)
{
}
nlohmann::json FlakeInput::toJson() const
{
auto json = FlakeInputs::toJson();
json.update(AbstractInput::toJson());
json["id"] = id;
return json;
}
FlakeInputs::FlakeInputs(const nlohmann::json & json)
{
for (auto & i : json["nonFlakeInputs"].items())
nonFlakeInputs.insert_or_assign(i.key(), NonFlakeInput(i.value()));
for (auto & i : json["inputs"].items())
flakeInputs.insert_or_assign(i.key(), FlakeInput(i.value()));
inputs.insert_or_assign(i.key(), LockedInput(i.value()));
}
nlohmann::json FlakeInputs::toJson() const
nlohmann::json LockedInputs::toJson() const
{
nlohmann::json json;
{
auto j = nlohmann::json::object();
for (auto & i : nonFlakeInputs)
for (auto & i : inputs)
j[i.first] = i.second.toJson();
json["nonFlakeInputs"] = std::move(j);
}
{
auto j = nlohmann::json::object();
for (auto & i : flakeInputs)
j[i.first.to_string()] = i.second.toJson();
json["inputs"] = std::move(j);
}
return json;
}
bool FlakeInputs::isDirty() const
bool LockedInputs::isDirty() const
{
for (auto & i : flakeInputs)
for (auto & i : inputs)
if (i.second.ref.isDirty() || i.second.isDirty()) return true;
for (auto & i : nonFlakeInputs)
if (i.second.ref.isDirty()) return true;
return false;
}
nlohmann::json LockFile::toJson() const
{
auto json = FlakeInputs::toJson();
auto json = LockedInputs::toJson();
json["version"] = 2;
return json;
}