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

Allow nixpkgs-check-by-name to work with recent Nix versions #79

Merged
merged 3 commits into from
Jul 26, 2024

Conversation

philiptaron
Copy link
Contributor

Fixes #78. I didn't root cause what the new behavior in the most recent Nix versions was that made the output of nix-instantiate different.

@philiptaron philiptaron requested a review from a team as a code owner July 8, 2024 20:38
@infinisil
Copy link
Member

infinisil commented Jul 12, 2024

Nice, this looks like the right fix! Could you also extend the test suite I mentioned in #78 (comment) with a case for this? Furthermore it would be great to have some comments giving the extra context

Edit: Also, let's increase the version number so we get a new release from this :)

test-nixpkgs-check-by-name.nix Outdated Show resolved Hide resolved
test-nixpkgs-check-by-name.nix Outdated Show resolved Hide resolved
default.nix Outdated Show resolved Hide resolved
@philiptaron
Copy link
Contributor Author

philiptaron commented Jul 14, 2024

Could you also extend the test suite I mentioned in #78 (comment) with a case for this?

I'm trying, but I have no idea how you generated that test case. 😬 All the test says is "these are what builtins.unsafeGetAttrPos returns", not how to get unsafeGetAttrPos to return that information about the above attrset.

Could you help me out with reproduction instructions? My best attempt is:

toInherit: {
  testA = 1;
  "testB" = 2;
  ${"testC"} = 3;
  "${"testD"}" = 4;
  # A
  testE
  # B
  =
  # C
  5
  # D
  ;
  # E

  /**/testF/**/=/**/5/**/;/*E*/

  testG = {
    valueG = 6;
  };

  inherit toInherit;
  inherit (toInherit) testH;
}
nix run nixpkgs#nixVersions.latest -- eval --expr 'let f = import ./test-nix-file.nix; value = f { testH = 8; }; in map (n: { inherit (builtins.unsafeGetAttrPos n value) line column; }) (builtins.attrNames value)' --impure --json | jq -r .

It's not helped out by unsafeGetAttrPos having no documentation whatsoever.

@infinisil
Copy link
Member

Oh yeah I can't quite remember how I got those numbers, probably just some trial-and-error, but obviously without actually running the final version through Nix eval, because the file in main is invalid :P

Your approach is pretty good though! I'm suggesting some changes:

testG: {
  testA = 1;
  "testB" = 2;
  ${"testC"} = 3;
  "${"testD"}" = 4;

  # A
  testE
  # B
  =
  # C
  5
  # D
  ;
  # E

  /**/testF/**/=/**/5/**/;/*E*/

  inherit testG;
  inherit ({}) testH;

  inherit ({})
    testI testJ
    testK testL;
}
nix run nixpkgs#nixVersions.latest -- eval --expr 'let value = import ./test.nix null; in builtins.mapAttrs (n: _: { inherit (builtins.unsafeGetAttrPos n value) line column; }) value' --impure --json | jq -r .

@philiptaron philiptaron force-pushed the issue-78/fix-inherit-io-issue branch from 52fd4a8 to d128f5e Compare July 15, 2024 16:56
@philiptaron philiptaron requested a review from infinisil July 16, 2024 18:24
@philiptaron
Copy link
Contributor Author

I'll do the requested version bump (and hence release) in a separate PR.

Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of time for now, but ended up spending a bunch of time to improve the testing with #83

Comment on lines +168 to +177
# Tests the tool on the pinned Nixpkgs tree with various Nix and Lix versions.
# This allows exposure to changes in behavior from Nix and Nix-alikes.
nixpkgsCheckWithLatestNix = packages.nixpkgsCheck.nixVersions.latest;
nixpkgsCheckWithGitNix = packages.nixpkgsCheck.nixVersions.git;
nixpkgsCheckWithMinimumNix = packages.nixpkgsCheck.nixVersions.minimum;
nixpkgsCheckWithStableLix = packages.nixpkgsCheck.lixVersions.stable;
nixpkgsCheckWithLatestLix = packages.nixpkgsCheck.lixVersions.latest;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is slowing down CI by about 3.5 minutes. I opened #83 instead to allow running the test suite with different Nix versions, which this PR can make use of.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way less important now that #83 is merged and the tool doesn't depend on the ambient version of Nix. I'm fine cutting them all, or going down to {minimum,stable,latest}.

That said, given that reviews are usually a matter of a week or more, 3.5 minutes more isn't an actual issue. Amdahl's law!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to keep these in the CI run. The number of PRs that aren't you or I is quite low.

src/nix_file.rs Show resolved Hide resolved
src/nix_file.rs Outdated
@@ -190,9 +190,7 @@ impl NixFile {
// Something like `foo`, `"foo"` or `${"foo"}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing, I found out that this is the branch also used for the foo in inherit (bar) foo in Nix > 2.20.

Suggested change
// Something like `foo`, `"foo"` or `${"foo"}`
// Something like `foo`, `"foo"` or `${"foo"}`
// For Nix versions > 2.20, this is also `foo` in `inherit (bar) foo`

src/nix_file.rs Outdated
@@ -190,9 +190,7 @@ impl NixFile {
// Something like `foo`, `"foo"` or `${"foo"}`
} else if ast::Inherit::can_cast(node.kind()) {
// Something like `inherit <attr>` or `inherit (<source>) <attr>`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Something like `inherit <attr>` or `inherit (<source>) <attr>`.
// Only for Nix versions <= 2.20: Something like `inherit <attr>` or `inherit (<source>) <attr>`.

src/nix_file.rs Show resolved Hide resolved
@philiptaron
Copy link
Contributor Author

I'll take the various suggestions about comments and fix it up to run the cargo tests under a plethora of Nix versions.

@philiptaron
Copy link
Contributor Author

philiptaron commented Jul 22, 2024

Nix eval using 2.3.18 (as performed by nixpkgs-check-by-name) is currently broken in nixpkgs master. NixOS/nixpkgs#329212 fixes it.

@philiptaron philiptaron force-pushed the issue-78/fix-inherit-io-issue branch from d128f5e to ba8bc85 Compare July 22, 2024 18:37
@philiptaron philiptaron marked this pull request as draft July 22, 2024 18:41
@philiptaron
Copy link
Contributor Author

philiptaron commented Jul 22, 2024

This is drafted until an update for nixpkgs causes eval on 2.3.18 to pass.

Edit on 2024-07-26: #88 unblocked this.

…x version

To run against a specific Nix or Lix version, run this:

```
nix-build -A nixpkgsCheck.nixVersions.nix_2_20
nix-build -A nixpkgsCheck.lixVersions.lix_2_90
```

To run against all Nix or Lix versions, run this:

```
nix-build -A nixpkgsCheck.nixVersions
nix-build -A nixpkgsCheck.lixVersions
```

CI will build the following versions:

* `nixpkgsCheck` (using `nixVersions.stable`)
* `nixpkgsCheckWithMinimumNix` (using `nixVersions.minimum`)
* `nixpkgsCheckWithLatestNix` (using `nixVersions.latest`)
* `nixpkgsCheckWithGitNix` (using `nixVersions.git`)
* `nixpkgsCheckWithStableLix` (using `lixVersions.stable`)
* `nixpkgsCheckWithLatestLix` (using `lixVersions.latest`)

These new tests exposes that Nix versions greater than 2.20 fail.

We don't currently have a derivation for unwrapped `nixpkgs-check-by-name`. Maybe soon.
…note

This exposes that Nix latest and all Lix versions fail.
This causes the following tests to pass:

- `nix-build -A nixpkgsCheck.nixVersions.nix_2_21`
- `nix-build -A nixpkgsCheck.nixVersions.nix_2_22`
- `nix-build -A nixpkgsCheck.nixVersions.nix_2_23`
- `nix-build -A nixpkgsCheck.nixVersions.git`
- `nix-build -A nixpkgsCheck.lixVersions.stable`

Add a regression test for this multiline inherit situation.

In that test, use `pretty_assertions` to get a nice diff expression for
the assertion, and make it do one assertion instead of asserting in a
loop.
@philiptaron philiptaron force-pushed the issue-78/fix-inherit-io-issue branch from ba8bc85 to bb1b9e1 Compare July 26, 2024 22:03
@philiptaron philiptaron marked this pull request as ready for review July 26, 2024 22:10
@philiptaron philiptaron requested a review from infinisil July 26, 2024 22:10
Copy link
Member

@infinisil infinisil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go! Thanks for this :D

@infinisil infinisil merged commit 725b75b into NixOS:main Jul 26, 2024
3 checks passed
@philiptaron philiptaron deleted the issue-78/fix-inherit-io-issue branch August 29, 2024 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

nixpkgs-check-by-name reports IO error for Nix versions 2.21+
2 participants