2019-06-04 21:01:21 +03:00
|
|
|
#pragma once
|
2023-04-01 06:18:41 +03:00
|
|
|
///@file
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
#include "flakeref.hh"
|
|
|
|
|
2019-10-21 23:11:21 +03:00
|
|
|
#include <nlohmann/json_fwd.hpp>
|
2019-06-04 21:01:21 +03:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
class Store;
|
2020-09-08 15:50:23 +03:00
|
|
|
class StorePath;
|
2019-06-04 21:01:21 +03: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 23:05:11 +02:00
|
|
|
typedef std::vector<FlakeId> InputPath;
|
|
|
|
|
2020-06-11 15:40:21 +03:00
|
|
|
struct LockedNode;
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* A node in the lock file. It has outgoing edges to other nodes (its
|
|
|
|
* inputs). Only the root node has this type; all other nodes have
|
|
|
|
* type LockedNode.
|
|
|
|
*/
|
2020-03-12 23:06:57 +02:00
|
|
|
struct Node : std::enable_shared_from_this<Node>
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2022-12-07 13:58:58 +02:00
|
|
|
typedef std::variant<ref<LockedNode>, InputPath> Edge;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2020-06-11 15:40:21 +03:00
|
|
|
std::map<FlakeId, Edge> inputs;
|
2020-03-09 16:28:41 +02:00
|
|
|
|
2020-06-11 15:40:21 +03:00
|
|
|
virtual ~Node() { }
|
2019-06-04 21:01:21 +03:00
|
|
|
};
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* A non-root node in the lock file.
|
|
|
|
*/
|
2020-03-12 23:06:57 +02:00
|
|
|
struct LockedNode : Node
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2020-02-02 01:05:53 +02:00
|
|
|
FlakeRef lockedRef, originalRef;
|
2020-03-09 16:27:49 +02:00
|
|
|
bool isFlake = true;
|
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
LockedNode(
|
2020-03-09 16:27:49 +02:00
|
|
|
const FlakeRef & lockedRef,
|
|
|
|
const FlakeRef & originalRef,
|
|
|
|
bool isFlake = true)
|
Remove TreeInfo
The attributes previously stored in TreeInfo (narHash, revCount,
lastModified) are now stored in Input. This makes it less arbitrary
what attributes are stored where.
As a result, the lock file format has changed. An entry like
"info": {
"lastModified": 1585405475,
"narHash": "sha256-bESW0n4KgPmZ0luxvwJ+UyATrC6iIltVCsGdLiphVeE="
},
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b88ff468e9850410070d4e0ccd68c7011f15b2be",
"type": "github"
},
is now stored as
"locked": {
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b88ff468e9850410070d4e0ccd68c7011f15b2be",
"type": "github",
"lastModified": 1585405475,
"narHash": "sha256-bESW0n4KgPmZ0luxvwJ+UyATrC6iIltVCsGdLiphVeE="
},
The 'Input' class is now a dumb set of attributes. All the fetcher
implementations subclass InputScheme, not Input. This simplifies the
API.
Also, fix substitution of flake inputs. This was broken since lazy
flake fetching started using fetchTree internally.
2020-05-30 01:44:11 +03:00
|
|
|
: lockedRef(lockedRef), originalRef(originalRef), isFlake(isFlake)
|
2020-01-21 17:27:53 +02:00
|
|
|
{ }
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
LockedNode(const nlohmann::json & json);
|
2019-08-30 17:27:51 +03:00
|
|
|
|
2020-01-30 01:13:37 +02:00
|
|
|
StorePath computeStorePath(Store & store) const;
|
2019-06-04 21:01:21 +03:00
|
|
|
};
|
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
struct LockFile
|
2019-06-04 21:01:21 +03:00
|
|
|
{
|
2022-12-07 13:58:58 +02:00
|
|
|
ref<Node> root = make_ref<Node>();
|
2020-03-12 23:06:57 +02:00
|
|
|
|
|
|
|
LockFile() {};
|
|
|
|
LockFile(const nlohmann::json & json, const Path & path);
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2022-12-07 13:58:58 +02:00
|
|
|
typedef std::map<ref<const Node>, std::string> KeyMap;
|
|
|
|
|
2024-02-16 18:00:07 +02:00
|
|
|
std::pair<nlohmann::json, KeyMap> toJSON() const;
|
2019-06-04 21:01:21 +03:00
|
|
|
|
2024-02-16 18:00:07 +02:00
|
|
|
std::pair<std::string, KeyMap> to_string() const;
|
2020-03-12 23:06:57 +02:00
|
|
|
|
2019-06-04 21:01:21 +03:00
|
|
|
static LockFile read(const Path & path);
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
2024-02-16 18:00:07 +02:00
|
|
|
* Check whether this lock file has any unlocked inputs. If so,
|
|
|
|
* return one.
|
2023-04-07 16:55:28 +03:00
|
|
|
*/
|
2022-12-07 13:58:58 +02:00
|
|
|
std::optional<FlakeRef> isUnlocked() const;
|
2020-03-12 23:06:57 +02:00
|
|
|
|
|
|
|
bool operator ==(const LockFile & other) const;
|
2023-04-07 14:08:32 +03:00
|
|
|
// Needed for old gcc versions that don't synthesize it (like gcc 8.2.2
|
2023-04-05 18:20:04 +03:00
|
|
|
// that is still the default on aarch64-linux)
|
|
|
|
bool operator !=(const LockFile & other) const;
|
2020-06-11 15:40:21 +03:00
|
|
|
|
|
|
|
std::shared_ptr<Node> findInput(const InputPath & path);
|
2020-06-12 00:34:02 +03:00
|
|
|
|
|
|
|
std::map<InputPath, Node::Edge> getAllInputs() const;
|
|
|
|
|
|
|
|
static std::string diff(const LockFile & oldLocks, const LockFile & newLocks);
|
|
|
|
|
2023-04-07 16:55:28 +03:00
|
|
|
/**
|
|
|
|
* Check that every 'follows' input target exists.
|
|
|
|
*/
|
2020-06-12 00:34:02 +03:00
|
|
|
void check();
|
2019-06-04 21:01:21 +03:00
|
|
|
};
|
|
|
|
|
2019-06-04 21:34:44 +03:00
|
|
|
std::ostream & operator <<(std::ostream & stream, const LockFile & lockFile);
|
|
|
|
|
2020-01-29 15:57:57 +02:00
|
|
|
InputPath parseInputPath(std::string_view s);
|
|
|
|
|
2020-06-10 16:20:00 +03:00
|
|
|
std::string printInputPath(const InputPath & path);
|
|
|
|
|
2019-06-04 21:01:21 +03:00
|
|
|
}
|