Skip to content

Commit

Permalink
flakes: Don't warn about meta and ellipsis except for root flake
Browse files Browse the repository at this point in the history
... and fix an incorrect use of `grep -v`
  • Loading branch information
roberth committed Sep 4, 2023
1 parent 1f739ff commit 72675eb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/manual/src/release-notes/rl-next.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

- The flake output function now accepts a parameter `meta`, which gives access to `sourceInfo` and such parameters in a robust manner, even when `self` can not be evaluated. This helps frameworks report error messages with locations, as trying to access the location previously resulted in an unhelpful infinite recursion when the error condition caused `self` to fail.

If an `outputs` function has a binding for all attributes (using `@`), you will be asked to add an ellipsis to avoid later confusion as to why `meta` is missing - which is necessary because of a limitation of Nix function semantics. This warning may occur in a dependency.
If an `outputs` function has a binding for all attributes (using `@`), you will be asked to add an ellipsis to avoid later confusion as to why `meta` is missing - which is necessary because of a limitation of Nix function semantics.

- Flake follow paths at depths greater than 2 are now handled correctly, preventing "follows a non-existent input" errors.

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/flake/call-flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ let
canRemove = isClosed && (builtins.functionBindsAllAttrs flake.outputs == false);

removals = if acceptsMeta then [] else [ "meta" ];
checked = if !acceptsMeta && !canRemove then warning else x: x;
checked = if isRoot && !acceptsMeta && !canRemove then warning else x: x;
warning = warn
"in flake ${toString outPath}: The flake's ${emphasize "outputs"} function does not accept the ${emphasize "meta"} argument.\nThis will become an error.\nPlease add ellipsis (${emphasize "..."}) to the function header for it to be compatible with both dated and upcoming versions of Flakes. Example use of ellipsis: ${emphasize "outputs = { self, ... }: "}.";
in
Expand Down
32 changes: 26 additions & 6 deletions tests/flakes/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ source common.sh

flakeDir=$TEST_ROOT/flake3
depDir=$TEST_ROOT/flakedep
mkdir -p $flakeDir $depDir
depDirB=$TEST_ROOT/flakedep2
mkdir -p $flakeDir $depDir $depDirB

cat > $depDir/flake.nix <<EOF
{
Expand Down Expand Up @@ -135,20 +136,39 @@ EOF

expectStderr 1 nix flake check $flakeDir | grep -F "flake input name 'meta' is reserved"


cat > $flakeDir/flake.nix <<EOF
echo cat \> $depDirB/flake.nix
cat > $depDirB/flake.nix <<EOF
{
inputs = {
};
outputs = args@{ self }:
# args won't have meta, as required by function semantics, but it is rather unfortunate, so Nix should warn about it.
# args won't have meta, as required by function semantics, but it is rather unfortunate,
# so Nix should warn about it, when this is the root flake.
assert !args?meta; # implied by function semantics
{
packages.$system = { };
};
}
EOF

nix flake check $depDirB 2>&1 | grep -F "Please add ellipsis"

cat $depDirB/flake.nix

# However it should not warn when the flake is used as a dependency, because in that case the user may not own the flake and can't change it. If they do own it, they only need to know about it when working on the flake itself.
cat > $flakeDir/flake.nix <<EOF
{
inputs = {
dep.url = "$depDirB";
};
outputs = { self, dep }:
builtins.seq dep.packages
{
};
}
EOF

nix flake check $flakeDir 2>&1 | grep -F "Please add ellipsis"
nix flake check $flakeDir 2>&1 | grepQuietInverse "Please add ellipsis"


cat > $flakeDir/flake.nix <<EOF
Expand All @@ -163,4 +183,4 @@ cat > $flakeDir/flake.nix <<EOF
}
EOF

nix flake check $flakeDir 2>&1 | grep -v "Please add ellipsis"
nix flake check $flakeDir 2>&1 | grepQuietInverse "Please add ellipsis"

0 comments on commit 72675eb

Please sign in to comment.