Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,29 @@ in
expected = "/our-nixpkgs";
};

input-overrides.test-follows-cycle-is-refused = {
expr =
(with-inputs
(
import ./fixtures/npins
// {
test2.outPath = ./fixtures/with-inputs-project2;
}
)
{
nixpkgs = mkSrc "/our-nixpkgs";
nixpkgs3.follows = "common-dep/x";
common-dep.follows = "nixpkgs3/y";
test3.outPath = ./fixtures/with-inputs-project3;
}
(inputs: {
res = inputs.test3.usedNixpkgs;
})
).res.outPath;
expectedError.type = "ThrownError";
expectedError.msg = "follows cycle";
};

# ── Dependency introspection ────────────────────────────────────────────────

introspection.test-access-sub-flake-inputs = {
Expand Down
18 changes: 15 additions & 3 deletions with-inputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,29 @@ let
let
recFollows =
let
# `seen`: the inputs already on this chain, so a follows cycle is refused by name, not a stack overflow.
follows =
input:
seen: input:
isFollows inputs.${input}
&& (
let
followRoot = builtins.head (builtins.split "/" inputs.${input}.follows);
chain = seen ++ [ input ];
cycle = builtins.concatStringsSep " -> " (chain ++ [ followRoot ]);
in
followRoot == name || (inputs ? ${followRoot} && follows followRoot)
followRoot == name
|| (
inputs ? ${followRoot}
&& (
if builtins.elem followRoot chain then
throw "with-inputs: follows cycle: ${cycle}"
else
follows chain followRoot
)
)
);
in
[ name ] ++ builtins.filter follows (builtins.attrNames inputs);
[ name ] ++ builtins.filter (follows [ ]) (builtins.attrNames inputs);
in
builtins.mapAttrs
(
Expand Down
Loading