2019-06-04 18:01:21 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "flakeref.hh"
|
|
|
|
|
2019-10-21 20:11:21 +00:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2019-06-04 18:01:21 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
class Store;
|
2020-01-29 23:13:37 +00:00
|
|
|
struct StorePath;
|
2019-06-04 18:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace nix::flake {
|
|
|
|
|
Respect lock files of inputs + fine-grained lock file control
When computing a lock file, we now respect the lock files of flake
inputs. This is important for usability / reproducibility. For
example, the 'nixops' flake depends on the 'nixops-aws' and
'nixops-hetzner' repositories. So when the 'nixops' flake is used in
another flake, we want the versions of 'nixops-aws' and
'nixops-hetzner' locked by the the 'nixops' flake because those
presumably have been tested.
This can lead to a proliferation of versions of flakes like 'nixpkgs'
(since every flake's lock file could depend on a different version of
'nixpkgs'). This is not a major issue when using Nixpkgs overlays or
NixOS modules, since then the top-level flake composes those
overlays/modules into *its* version of Nixpkgs and all other versions
are ignored. Lock file computation has been made a bit more lazy so it
won't try to fetch all those versions of 'nixpkgs'.
However, in case it's necessary to minimize flake versions, there now
are two input attributes that allow this. First, you can copy an input
from another flake, as follows:
inputs.nixpkgs.follows = "dwarffs/nixpkgs";
This states that the calling flake's 'nixpkgs' input shall be the same
as the 'nixpkgs' input of the 'dwarffs' input.
Second, you can override inputs of inputs:
inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
inputs.nixops.inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
or equivalently, using 'follows':
inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
inputs.nixops.inputs.nixpkgs.follows = "nixpkgs";
This states that the 'nixpkgs' input of the 'nixops' input shall be
the same as the calling flake's 'nixpkgs' input.
Finally, at '-v' Nix now prints the changes to the lock file, e.g.
$ nix flake update ~/Misc/eelco-configurations/hagbard
inputs of flake 'git+file:///home/eelco/Misc/eelco-configurations?subdir=hagbard' changed:
updated 'nixpkgs': 'github:edolstra/nixpkgs/7845bf5f4b3013df1cf036e9c9c3a55a30331db9' -> 'github:edolstra/nixpkgs/03f3def66a104a221aac8b751eeb7075374848fd'
removed 'nixops'
removed 'nixops/nixops-aws'
removed 'nixops/nixops-hetzner'
removed 'nixops/nixpkgs'
2020-01-24 21:05:11 +00:00
|
|
|
typedef std::vector<FlakeId> InputPath;
|
|
|
|
|
2019-08-30 14:27:51 +00:00
|
|
|
struct LockedInput;
|
2019-06-04 18:01:21 +00:00
|
|
|
|
|
|
|
/* Lock file information about the dependencies of a flake. */
|
2019-08-30 14:27:51 +00:00
|
|
|
struct LockedInputs
|
2019-06-04 18:01:21 +00:00
|
|
|
{
|
2019-08-30 14:27:51 +00:00
|
|
|
std::map<FlakeId, LockedInput> inputs;
|
2019-06-04 18:01:21 +00:00
|
|
|
|
2019-08-30 14:27:51 +00:00
|
|
|
LockedInputs() {};
|
|
|
|
LockedInputs(const nlohmann::json & json);
|
2019-06-04 18:01:21 +00:00
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
2019-07-12 11:29:54 +00:00
|
|
|
|
2020-01-21 15:27:53 +00:00
|
|
|
bool isImmutable() const;
|
Respect lock files of inputs + fine-grained lock file control
When computing a lock file, we now respect the lock files of flake
inputs. This is important for usability / reproducibility. For
example, the 'nixops' flake depends on the 'nixops-aws' and
'nixops-hetzner' repositories. So when the 'nixops' flake is used in
another flake, we want the versions of 'nixops-aws' and
'nixops-hetzner' locked by the the 'nixops' flake because those
presumably have been tested.
This can lead to a proliferation of versions of flakes like 'nixpkgs'
(since every flake's lock file could depend on a different version of
'nixpkgs'). This is not a major issue when using Nixpkgs overlays or
NixOS modules, since then the top-level flake composes those
overlays/modules into *its* version of Nixpkgs and all other versions
are ignored. Lock file computation has been made a bit more lazy so it
won't try to fetch all those versions of 'nixpkgs'.
However, in case it's necessary to minimize flake versions, there now
are two input attributes that allow this. First, you can copy an input
from another flake, as follows:
inputs.nixpkgs.follows = "dwarffs/nixpkgs";
This states that the calling flake's 'nixpkgs' input shall be the same
as the 'nixpkgs' input of the 'dwarffs' input.
Second, you can override inputs of inputs:
inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
inputs.nixops.inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
or equivalently, using 'follows':
inputs.nixpkgs.url = github:edolstra/nixpkgs/<hash>;
inputs.nixops.inputs.nixpkgs.follows = "nixpkgs";
This states that the 'nixpkgs' input of the 'nixops' input shall be
the same as the calling flake's 'nixpkgs' input.
Finally, at '-v' Nix now prints the changes to the lock file, e.g.
$ nix flake update ~/Misc/eelco-configurations/hagbard
inputs of flake 'git+file:///home/eelco/Misc/eelco-configurations?subdir=hagbard' changed:
updated 'nixpkgs': 'github:edolstra/nixpkgs/7845bf5f4b3013df1cf036e9c9c3a55a30331db9' -> 'github:edolstra/nixpkgs/03f3def66a104a221aac8b751eeb7075374848fd'
removed 'nixops'
removed 'nixops/nixops-aws'
removed 'nixops/nixops-hetzner'
removed 'nixops/nixpkgs'
2020-01-24 21:05:11 +00:00
|
|
|
|
|
|
|
std::optional<LockedInput *> findInput(const InputPath & path);
|
2020-01-29 22:12:58 +00:00
|
|
|
|
|
|
|
void removeInput(const InputPath & path);
|
2019-06-04 18:01:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Lock file information about a flake input. */
|
2019-08-30 14:27:51 +00:00
|
|
|
struct LockedInput : LockedInputs
|
2019-06-04 18:01:21 +00:00
|
|
|
{
|
2019-09-18 19:17:27 +00:00
|
|
|
FlakeRef ref, originalRef;
|
2020-02-01 22:33:44 +00:00
|
|
|
TreeInfo info;
|
2019-06-04 18:01:21 +00:00
|
|
|
|
2020-02-01 22:33:44 +00:00
|
|
|
LockedInput(const FlakeRef & ref, const FlakeRef & originalRef, const TreeInfo & info)
|
|
|
|
: ref(ref), originalRef(originalRef), info(info)
|
2020-01-21 15:27:53 +00:00
|
|
|
{ }
|
2019-06-04 18:01:21 +00:00
|
|
|
|
2019-08-30 14:27:51 +00:00
|
|
|
LockedInput(const nlohmann::json & json);
|
2019-06-04 18:01:21 +00:00
|
|
|
|
2019-08-30 14:27:51 +00:00
|
|
|
bool operator ==(const LockedInput & other) const
|
2019-06-04 18:01:21 +00:00
|
|
|
{
|
|
|
|
return
|
2019-08-30 14:27:51 +00:00
|
|
|
ref == other.ref
|
2020-02-01 22:33:44 +00:00
|
|
|
&& originalRef == other.originalRef
|
|
|
|
&& info == other.info
|
2019-08-30 14:27:51 +00:00
|
|
|
&& inputs == other.inputs;
|
2019-06-04 18:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
2019-08-30 14:27:51 +00:00
|
|
|
|
2020-01-29 23:13:37 +00:00
|
|
|
StorePath computeStorePath(Store & store) const;
|
2019-06-04 18:01:21 +00:00
|
|
|
};
|
|
|
|
|
2019-06-04 18:08:13 +00:00
|
|
|
/* An entire lock file. Note that this cannot be a FlakeInput for the
|
2019-06-04 18:01:21 +00:00
|
|
|
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. */
|
2019-08-30 14:27:51 +00:00
|
|
|
struct LockFile : LockedInputs
|
2019-06-04 18:01:21 +00:00
|
|
|
{
|
|
|
|
bool operator ==(const LockFile & other) const
|
|
|
|
{
|
2019-08-30 14:27:51 +00:00
|
|
|
return inputs == other.inputs;
|
2019-06-04 18:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LockFile() {}
|
2019-08-30 14:27:51 +00:00
|
|
|
LockFile(const nlohmann::json & json) : LockedInputs(json) {}
|
|
|
|
LockFile(LockedInput && dep)
|
2019-06-04 18:01:21 +00:00
|
|
|
{
|
2019-08-30 14:27:51 +00:00
|
|
|
inputs = std::move(dep.inputs);
|
2019-06-04 18:01:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nlohmann::json toJson() const;
|
|
|
|
|
|
|
|
static LockFile read(const Path & path);
|
|
|
|
|
|
|
|
void write(const Path & path) const;
|
|
|
|
};
|
|
|
|
|
2019-06-04 18:34:44 +00:00
|
|
|
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile);
|
|
|
|
|
2020-01-29 13:57:57 +00:00
|
|
|
InputPath parseInputPath(std::string_view s);
|
|
|
|
|
2019-06-04 18:01:21 +00:00
|
|
|
}
|
|
|
|
|