aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/flake/call-flake.nix
blob: 8ee17b8f4ac1ec1bf4021e7efaa62d4e2e71b8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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}