Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a warning on an implicit input specification. #4072

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Generate a warning on an implicit input specification.
The ability to implicitly specify inputs as referencing flakes of the
same name is not specifically identified by the documentation (and
it's not clear if this behavior is intended to remain in the future).

If there is a typographical mismatch between an explicit input name
and the argument used for the `output`, this will result in a more
obscure error "cannot find flake 'flake:foo' in the flake registries",
which leads the user in the direction of managing the registries
instead of noticing the mis-spelling.

By adding a warning when an implicit input is created, it can make it
easier for the user to identify whether this was intended or whether
they have made an erroneous typo resulting in mismatched names.
  • Loading branch information
kquick committed Sep 25, 2020
commit 7552d3c5b9ea15b831e5cde5b6363c727eeb757f
7 changes: 5 additions & 2 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,14 @@ static Flake getFlake(

if (outputs->value->lambda.fun->matchAttrs) {
for (auto & formal : outputs->value->lambda.fun->formals->formals) {
if (formal.name != state.sSelf)
if (formal.name != state.sSelf) {
if (!flake.inputs.count(formal.name))
warn("implicit flake:%s input via output function argument in %s", formal.name, lockedRef);
flake.inputs.emplace(formal.name, FlakeInput {
.ref = parseFlakeRef(formal.name)
});
}
};
};
}

} else
Expand Down
47 changes: 47 additions & 0 deletions tests/flakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,53 @@ nix build -o $TEST_ROOT/result --no-registries git+file:https://$flake2Dir#bar --refre
nix build -o $TEST_ROOT/result $flake3Dir#xyzzy
git -C $flake3Dir add flake.lock

# Check how non-existent implicit input references are handled with
# body eval errors
rm $flake3Dir/flake.nix

cat > $flake3Dir/flake.nix <<EOF
{
description = "Fnord";

outputs = { self, noflake }: rec {
packages.$system.xyzzy = nofluke.packages.$system.foo;
};
}
EOF

git -C $flake3Dir add flake.nix
git -C $flake3Dir commit -m 'Update flake.nix with fluke'

err=$flake3Dir/impl.errout
! nix build -o $TEST_ROOT/result $flake3Dir#xyzzy 2>$err
cat $err
grep -q UndefinedVarError $err
grep -q nofluke $err

# Check how non-existent implicit input references are handled
rm $flake3Dir/flake.nix

cat > $flake3Dir/flake.nix <<EOF
{
description = "Fnord";

outputs = { self, noflake }: rec {
packages.$system.xyzzy = noflake.packages.$system.foo;
};
}
EOF

git -C $flake3Dir add flake.nix
git -C $flake3Dir commit -m 'Update flake.nix with fluke'

err=$flake3Dir/impl.errout
! nix build -o $TEST_ROOT/result $flake3Dir#xyzzy
! nix build -o $TEST_ROOT/result $flake3Dir#xyzzy 2>$err
cat $err
grep "warning: implicit flake:noflake input via output function argument in git+file:https:///build/nix-test/flakes/flake3" $err
grep error $err
grep "cannot find flake 'flake:noflake' in the flake registries" $err

# Add dependency to flake3.
rm $flake3Dir/flake.nix

Expand Down