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

neovim: add a checkPhase in the wrapper #352727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

teto
Copy link
Member

@teto teto commented Oct 31, 2024

add a checkPhase (if doCheck == true, disabled by default) that tries to start neovim and fails in case of errors. It allows to catch small misconfiugurations before switching to a new config.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@khaneliman
Copy link
Contributor

Seems to crash nixpkgs-review
image

Comment on lines 61 to 62
# build should fail when this gets uncommented
# luaRcContent = "toto";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to stay ? I see how it can be an example.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was not sure how to test for a build failure. So I added this to be able to check. Happy to remove it or you have another suggestion

Copy link
Contributor

@MattSturgeon MattSturgeon Nov 2, 2024

Choose a reason for hiding this comment

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

I was not sure how to test for a build failure.

You can use pkgs.testers.testBuildFailure to make a test that passes when the derivation you pass to it fails.

We use this in nixvim: https://github.com/nix-community/nixvim/blob/main/tests/failing-tests.nix

@@ -147,7 +148,7 @@ let

pname = "neovim";
version = lib.getVersion neovim-unwrapped;
in {
in builtins.removeAttrs attrs ["extraPython3Packages" "extraLuaPackages" ] // {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that related to enabling the check phase ?

Copy link
Member Author

Choose a reason for hiding this comment

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

instead of adding inherit doCheck I thought I could remove all the inherit withPython, etc by directly reusing the removeAttrs. Except I haven't removed the other withXX so it's a bit redundant :/ Had to remove everything that is a function from attrs since nix cant serialize it

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I see... Feels a bit hacky no ?

Copy link
Member Author

Choose a reason for hiding this comment

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

that's how most builders work so I am not sure. It's a style tradeoff. Anyhow I've reverted it since it seems confusing and might have some unforeseen consequences

@khaneliman
Copy link
Contributor

khaneliman commented Nov 2, 2024

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 352727


x86_64-darwin

✅ 5 packages built:
  • gnvim
  • lunarvim
  • neovim-qt
  • nvimpager
  • vim-startuptime

aarch64-darwin

❌ 1 package failed to build:
  • neovide
✅ 5 packages built:
  • gnvim
  • lunarvim
  • neovim-qt
  • nvimpager
  • vim-startuptime

Neovide is broken on master already.

[183/1513] link libjpeg.a
┃        >   FAILED: libjpeg.a
┃        >   libtool -static -o libjpeg.a -no_warning_for_no_symbols obj/third_party/externals/libjpeg-turbo/libjpeg.jaricom.o obj/third_party/externals/libjpeg-turbo/libjpeg.jcapimi…
┃        >   /bin/sh: libtool: command not found
┃        >   [184/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-subset-cff-common.cc
┃        >   [185/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-ucd.cc
┃        >   [186/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-ot-shaper-arabic.cc
┃        >   [187/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-unicode.cc
┃        >   [188/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-static.cc
┃        >   [189/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-subset-repacker.cc
┃        >   [190/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-subset-cff2.cc
┃        >   [191/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-subset-cff1.cc
┃        >   [192/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-ot-layout.cc
┃        >   [193/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-subset-plan.cc
┃        >   [194/1513] compile ../../../../../../../../../../../nix/store/myxqsdsyb1571wmgh455cjlhlmwjyis2-source/third_party/externals/harfbuzz/src/hb-subset.cc
┃        >   ninja: build stopped: subcommand failed.

@teto
Copy link
Member Author

teto commented Nov 3, 2024

@MattSturgeon thanks for the pkgs.testers.testBuildFailure tip.
I've tried to use it but seems like it doesn't like the __structuredAttrs check because of shell hardening.

$ nix-build -A neovim.tests.failed_check
these 2 derivations will be built:
 /nix/store/1w8g4rcvzazrz1zlk657gclnpavn5h6q-init.lua.drv
 /nix/store/8wz4lh3a825mvfa40miadpzcnmlrarf5-neovim-0.10.2.drv
building '/nix/store/1w8g4rcvzazrz1zlk657gclnpavn5h6q-init.lua.drv'...
building '/nix/store/8wz4lh3a825mvfa40miadpzcnmlrarf5-neovim-0.10.2.drv'...
testBuildFailure: Expecting non-zero exit from builder and args: '/nix/store/mm0pa3z7kk6jh1i9rkxqxjqmd8h1qpxf-bash-5.2p37/bin/bash' '-e' '/nix/store/v6x3cs394jgqfbi0a42pam708flxaphh-default-builder.sh'
original builder: structuredAttrs is enabled
original builder: Running phase: patchPhase
original builder: @nix { "action": "setPhase", "phase": "patchPhase" }
original builder: Running phase: updateAutotoolsGnuConfigScriptsPhase
original builder: @nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
original builder: Running phase: configurePhase
original builder: @nix { "action": "setPhase", "phase": "configurePhase" }
....
      > original builder: _addToLuaPath called for dir /nix/store/j7065pwakq2f2nrshwi5c6qh7fnqg3d0-vim-pack-dir
      > original builder: LUA_PATH towards the end of packdir: ;;
      > original builder: Running phase: checkPhase
      > original builder: @nix { "action": "setPhase", "phase": "checkPhase" }
      > original builder: Error detected while processing /nix/store/bx0dbsfnnkg94yaarw9livpwxk49anvg-init.lua:
      > testBuildFailure: Original builder produced exit code: 1
      > /nix/store/ms79njxnpys354nc5n9v27qh4i5g1gjj-expect-failure.sh: line 37: __structuredAttrs: unbound variable
      For full logs, run 'nix log /nix/store/8wz4lh3a825mvfa40miadpzcnmlrarf5-neovim-0.10.2.drv'.
      

@Artturin seems like you touched expect-failure.sh last. Is it because of set -u ?
should if [ -n "$__structuredAttrs" ]; then be if [ -v "__structuredAttrs" ]; then instead ? I tried and it seems to work until I get to

        echo "${!outputs[*]}"

which fails with

       > original builder: @nix { "action": "setPhase", "phase": "checkPhase" }
       > original builder: Error detected while processing /nix/store/bx0dbsfnnkg94yaarw9livpwxk49anvg-init.lua:
       > testBuildFailure: Original builder produced exit code: 1
       > /nix/store/gb8s8251da5zap4d1rxlpiv37skim3gm-expect-failure.sh: line 40: outputs: unbound variable

Should I wrap the call in

runCommand "example" {
  failed = testers.testBuildFailure (....
} ''
  grep -F 'failing though' $failed/testBuildFailure.log
  [[ 3 = $(cat $failed/testBuildFailure.exit) ]]
  touch $out
''

as presented in the doc ?

@MattSturgeon
Copy link
Contributor

MattSturgeon commented Nov 3, 2024

@MattSturgeon thanks for the pkgs.testers.testBuildFailure tip.

No problem 😁

I've tried to use it but seems like it doesn't like the __structuredAttrs check because of shell hardening.

🤔 Is it a build failure or an eval error you're testing for? testBuildFailure can only handle build failures; eval errors will still leak through.

Should I wrap the call in

runCommand "example" {
  failed = testers.testBuildFailure (....
} ''
  grep -F 'failing though' $failed/testBuildFailure.log
  [[ 3 = $(cat $failed/testBuildFailure.exit) ]]
  touch $out
''

as presented in the doc ?

That's what we do in nixvim; pass the failing derivation into another test that can assert it failed in the expected way.

Copy link
Member

@PerchunPak PerchunPak left a comment

Choose a reason for hiding this comment

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

If nixpkgs-review passes, LGTM. Nice and simple feature

Though maybe document it somewhere?

$out/bin/nvim -i NONE -e +quitall!
runHook postCheck
'';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'';
'';

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 5, 2024
add a checkPhase (if doCheck == true, disabled by default) that tries to
start neovim and fails in case of errors. It allows to catch small
misconfiugurations before switching to a new config.
@github-actions github-actions bot removed the 6.topic: testing Tooling for automated testing of packages and modules label Nov 14, 2024
@wegank wegank removed the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 14, 2024
@teto
Copy link
Member Author

teto commented Nov 14, 2024

pass the failing derivation into another test that can assert it failed in the expected way.

it would be better but this should work as is, without needing to check for the failure.

Though maybe document it somewhere?

Issue is this appears only in the unstable wrapper. Neovim being popular we've tried to maintain compatibility with the old wrapper to not break configs. I think the new wrapper is better enough than the old one so we can switch. It is something to approach carefully though so let it be for 25.04.
I really want to have the doc generated from code as well so I've opened nix-community/nixdoc#137 .

I would like to use this PR feature to update the neovim tests so I am going to merge even if it means disabling the doCheck test. I've opened #355953 for a fix to enable the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants