2024-02-16 18:00:07 +02:00
|
|
|
# This is a helper to callFlake() to lazily fetch flake inputs.
|
|
|
|
|
|
|
|
# The contents of the lock file, in JSON format.
|
|
|
|
lockFileStr:
|
|
|
|
|
|
|
|
# A mapping of lock file node IDs to { sourceInfo, subdir } attrsets,
|
2024-05-06 18:29:03 +03:00
|
|
|
# with sourceInfo.outPath providing an SourceAccessor to a previously
|
2024-02-16 18:00:07 +02:00
|
|
|
# fetched tree. This is necessary for possibly unlocked inputs, in
|
|
|
|
# particular the root input, but also --override-inputs pointing to
|
|
|
|
# unlocked trees.
|
|
|
|
overrides:
|
2020-03-09 16:28:41 +02:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
lockFile = builtins.fromJSON lockFileStr;
|
2020-03-09 16:28:41 +02:00
|
|
|
|
2024-02-16 18:00:07 +02:00
|
|
|
# Resolve a input spec into a node name. An input spec is
|
|
|
|
# either a node name, or a 'follows' path from the root
|
|
|
|
# node.
|
|
|
|
resolveInput = inputSpec:
|
|
|
|
if builtins.isList inputSpec
|
|
|
|
then getInputByPath lockFile.root inputSpec
|
|
|
|
else inputSpec;
|
|
|
|
|
|
|
|
# Follow an input path (e.g. ["dwarffs" "nixpkgs"]) from the
|
|
|
|
# root node, returning the final node.
|
|
|
|
getInputByPath = nodeName: path:
|
|
|
|
if path == []
|
|
|
|
then nodeName
|
|
|
|
else
|
|
|
|
getInputByPath
|
|
|
|
# Since this could be a 'follows' input, call resolveInput.
|
|
|
|
(resolveInput lockFile.nodes.${nodeName}.inputs.${builtins.head path})
|
|
|
|
(builtins.tail path);
|
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
allNodes =
|
|
|
|
builtins.mapAttrs
|
|
|
|
(key: node:
|
|
|
|
let
|
2020-06-11 15:40:21 +03:00
|
|
|
|
2023-02-22 04:28:30 +02:00
|
|
|
sourceInfo =
|
2024-02-16 18:00:07 +02:00
|
|
|
if overrides ? ${key}
|
|
|
|
then
|
|
|
|
overrides.${key}.sourceInfo
|
|
|
|
else
|
|
|
|
# FIXME: remove obsolete node.info.
|
|
|
|
fetchTree (node.info or {} // removeAttrs node.locked ["dir"]);
|
2020-06-11 15:40:21 +03:00
|
|
|
|
2024-02-16 18:00:07 +02:00
|
|
|
subdir = overrides.${key}.dir or node.locked.dir or "";
|
2020-06-11 15:40:21 +03:00
|
|
|
|
2023-02-22 04:28:30 +02:00
|
|
|
outPath = sourceInfo + ((if subdir == "" then "" else "/") + subdir);
|
2023-02-09 23:10:30 +02:00
|
|
|
|
|
|
|
flake = import (outPath + "/flake.nix");
|
2020-06-11 15:40:21 +03:00
|
|
|
|
|
|
|
inputs = builtins.mapAttrs
|
|
|
|
(inputName: inputSpec: allNodes.${resolveInput inputSpec})
|
|
|
|
(node.inputs or {});
|
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
outputs = flake.outputs (inputs // { self = result; });
|
2020-06-11 15:40:21 +03:00
|
|
|
|
2023-02-22 04:28:30 +02:00
|
|
|
result =
|
|
|
|
outputs
|
|
|
|
# We add the sourceInfo attribute for its metadata, as they are
|
|
|
|
# relevant metadata for the flake. However, the outPath of the
|
|
|
|
# sourceInfo does not necessarily match the outPath of the flake,
|
|
|
|
# as the flake may be in a subdirectory of a source.
|
|
|
|
# This is shadowed in the next //
|
|
|
|
// sourceInfo
|
|
|
|
// {
|
|
|
|
# This shadows the sourceInfo.outPath
|
|
|
|
inherit outPath;
|
|
|
|
|
|
|
|
inherit inputs; inherit outputs; inherit sourceInfo; _type = "flake";
|
|
|
|
};
|
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
in
|
|
|
|
if node.flake or true then
|
|
|
|
assert builtins.isFunction flake.outputs;
|
|
|
|
result
|
|
|
|
else
|
|
|
|
sourceInfo
|
|
|
|
)
|
|
|
|
lockFile.nodes;
|
2020-03-09 16:28:41 +02:00
|
|
|
|
2020-03-12 23:06:57 +02:00
|
|
|
in allNodes.${lockFile.root}
|