forked from lix-project/lix
e5ea01c1a8
Future editions of flakes or the Nix language can be supported by renaming flake.nix (e.g. flake-v2.nix). This avoids a bootstrap problem where we don't know which grammar to use to parse flake*.nix. It also allows a project to support multiple flake editions, in theory.
30 lines
998 B
Nix
30 lines
998 B
Nix
lockFileStr: rootSrc: rootSubdir:
|
|
|
|
let
|
|
|
|
lockFile = builtins.fromJSON lockFileStr;
|
|
|
|
allNodes =
|
|
builtins.mapAttrs
|
|
(key: node:
|
|
let
|
|
sourceInfo =
|
|
if key == lockFile.root
|
|
then rootSrc
|
|
else fetchTree ({ inherit (node.info) narHash; } // removeAttrs node.locked ["dir"]);
|
|
subdir = if key == lockFile.root then rootSubdir else node.locked.dir or "";
|
|
flake = import (sourceInfo + (if subdir != "" then "/" else "") + subdir + "/flake.nix");
|
|
inputs = builtins.mapAttrs (inputName: key: allNodes.${key}) (node.inputs or {});
|
|
outputs = flake.outputs (inputs // { self = result; });
|
|
result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
|
|
in
|
|
if node.flake or true then
|
|
assert builtins.isFunction flake.outputs;
|
|
result
|
|
else
|
|
sourceInfo
|
|
)
|
|
lockFile.nodes;
|
|
|
|
in allNodes.${lockFile.root}
|