lix/src/libexpr/flake/lockfile.hh
Eelco Dolstra 30ccf4e52d 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;
    };
  };
2019-08-30 16:27:51 +02:00

86 lines
1.8 KiB
C++

#pragma once
#include "flakeref.hh"
#include <nlohmann/json.hpp>
namespace nix {
class Store;
}
namespace nix::flake {
struct LockedInput;
/* Lock file information about the dependencies of a flake. */
struct LockedInputs
{
std::map<FlakeId, LockedInput> inputs;
LockedInputs() {};
LockedInputs(const nlohmann::json & json);
nlohmann::json toJson() const;
/* A lock file is dirty if it contains a dirty flakeref
(i.e. reference to a dirty working tree). */
bool isDirty() const;
};
/* Lock file information about a flake input. */
struct LockedInput : LockedInputs
{
FlakeRef ref;
Hash narHash;
LockedInput(const FlakeRef & ref, const Hash & narHash)
: ref(ref), narHash(narHash)
{
assert(ref.isImmutable());
};
LockedInput(const nlohmann::json & json);
bool operator ==(const LockedInput & other) const
{
return
ref == other.ref
&& narHash == other.narHash
&& inputs == other.inputs;
}
nlohmann::json toJson() const;
Path computeStorePath(Store & store) const;
};
/* An entire lock file. Note that this cannot be a FlakeInput for the
top-level flake, because then the lock file would need to contain
the hash of the top-level flake, but committing the lock file
would invalidate that hash. */
struct LockFile : LockedInputs
{
bool operator ==(const LockFile & other) const
{
return inputs == other.inputs;
}
LockFile() {}
LockFile(const nlohmann::json & json) : LockedInputs(json) {}
LockFile(LockedInput && dep)
{
inputs = std::move(dep.inputs);
}
nlohmann::json toJson() const;
static LockFile read(const Path & path);
void write(const Path & path) const;
};
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile);
}