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

nix flake check: skip derivations for foreign systems #7759

Conversation

peterbecich
Copy link
Contributor

@peterbecich peterbecich commented Feb 5, 2023

Context

nix flake check breaks on IFD in multi-platform flake
#4265

This PR changes the default behavior of nix flake check.

The same change was already approved for nix flake show: #6988

Motivation

nix flake show now skips derivations for foreign systems: #6988

This PR borrows from that PR to implement the same behavior for nix flake check.

Here is a Flake project which I believe uses IFD: https://github.com/srid/haskell-template

Using Nix 2.12.0 on a x86_64-linux, the result of nix flake check is:

$ nix flake check
warning: Git tree '/home/peterbecich/haskell/libraries/haskell-template' is dirty
error: a 'aarch64-linux' with features {} is required to build 
'/nix/store/jlcg48nsm1dpblvg9wj6zq19c3mswg40-cabal2nix-haskell-template.drv',
 but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}
(use '--show-trace' to show detailed location information)

With this PR, nix flake check produces:

~/nix/nix/outputs/out/bin/nix flake check
warning: Git tree '/home/peterbecich/haskell/libraries/haskell-template' is dirty
warning: The check omitted these incompatible systems (use '--all-systems' to check all):
warning: aarch64-darwin
warning: aarch64-linux
warning: armv5tel-linux
warning: armv6l-linux
warning: armv7l-linux
warning: i686-linux
warning: mipsel-linux
warning: powerpc64le-linux
warning: riscv64-linux
warning: x86_64-darwin

With this PR and the --all-systems flag, it produces an error like before:

 ~/nix/nix/outputs/out/bin/nix flake check --all-systems
warning: Git tree '/home/peterbecich/haskell/libraries/haskell-template' is dirty
error:
       … while checking flake output 'packages'

         at «none»:0: (source not available)

       … while checking the derivation 'packages.aarch64-linux.default'

         at «none»:0: (source not available)

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: a 'aarch64-linux' with features {} is required to build 
'/nix/store/jlcg48nsm1dpblvg9wj6zq19c3mswg40-cabal2nix-haskell-template.drv',
 but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}

The current system is acquired this way, copied from #6988:

auto localSystem = std::string(settings.thisSystem.get());

For a Nix system with remote builders, could this change to the default behavior of nix flake check be a problem?

This PR copies the existing check checkSystemName.
Wherever checkSystemName is applied in nix flake check, the system type is now also checked by checkSystemType. I have not thought very carefully about where these checks are placed. Example:

nix/src/nix/flake.cc

Lines 528 to 542 in 8be71bc

checkSystemName(attr_name, attr.pos);
if (checkSystemType(attr_name, attr.pos)) {
state->forceAttrs(*attr.value, attr.pos, "");
for (auto & attr2 : *attr.value->attrs) {
auto drvPath = checkDerivation(
fmt("%s.%s.%s", name, attr_name, state->symbols[attr2.name]),
*attr2.value, attr2.pos);
if (drvPath && attr_name == settings.thisSystem.get()) {
drvPaths.push_back(DerivedPath::Built {
.drvPath = *drvPath,
.outputs = OutputsSpec::All { },
});
}
}
}

Checklist for maintainers

Maintainers: tick if completed or explain if not relevant

  • agreed on idea
  • agreed on implementation strategy
  • tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • documentation in the manual
  • code and comments are self-explanatory
  • commit message explains why the change was made
  • new feature or bug fix: updated release notes

@yajo
Copy link
Contributor

yajo commented Feb 6, 2023

If you want better backwards compatibility, you can do this opt-in and instead add the flag --current-system-only or --skip-foreign-systems or similar.

@peterbecich peterbecich marked this pull request as ready for review February 7, 2023 04:22
@peterbecich
Copy link
Contributor Author

peterbecich commented Feb 7, 2023

That's a good idea, I don't have an opinion one way or the other.

Can somebody make a decision:

  • check all systems by default; --current-system-only flag or similar
    • optionally, we could consider altering nix flake show to be consistent with this

or

  • check only current system by default; --all-systems flag
    • consistent with nix flake show --all-systems

I assume the nix flake show fix will be included in the 2.14 release. It would be cool if this PR were also included in 2.14.

@NobbZ
Copy link
Contributor

NobbZ commented Feb 7, 2023

Personally I am in the "change the default behaviour" camp and only check the current system.

This usually makes it easier to run a check on the terminal.

Keeping the current behaviour as the default would usually end up in a workflow like the following:

  1. run the check,
  2. see it fail because of IFD
  3. be confused
  4. google
  5. try check with --current-system-only (or whatever name would be agreed upon)
  6. see an error that the flag wasn't known as nix is too old

Optionally replace 6 with "get a suceeding check".

By changing the default, we can get this down to:

  1. run the check
  2. see it pass/fail

In worst case people had an older nix and they would google and should see, oh, new behaviour introduced in nix 2.30, I'm only on 2.15, so I have to update.

CI that indeed relies on multi-arch checks would need to update their scripts, as they update their nix version. I think this is fine. At least they are relying on experimental software which is allowed to break or change its behaviour in subtle ways.

We just need to be clear in the release notes that this is intended behaviour.

Break things now!

Once 3.0 got released we can not as easily!

PS: I am a big fan of --system … to be able to override the current system to play with aarch64 and i686 builds on my x86_64 box, so that should definitely be respected as "current system"

@peterbecich
Copy link
Contributor Author

Okay, I will keep the current behavior then, default is current system only.

PS: I am a big fan of --system … to be able to override the current system to play with aarch64 and i686 builds on my x86_64 box, so that should definitely be respected as "current system"

This is a good idea; can we review this PR now and implement that later in a subsequent PR? It can be done for both nix flake show and nix flake check. I don't know when the date is for the next release; hoping to merge this PR before.

@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch 2 times, most recently from ab46217 to b2e5a8a Compare February 11, 2023 07:38
@fricklerhandwerk fricklerhandwerk changed the title nix flake check skips derivations for foreign systems nix flake check: skip derivations for foreign systems Feb 17, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-02-17-nix-team-meeting-minutes-33/25624/1

@thufschmitt thufschmitt added the new-cli Relating to the "nix" command label Feb 27, 2023
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-02-17-nix-team-meeting-minutes-33/25624/2

@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from b2e5a8a to 15d7393 Compare March 11, 2023 02:53
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Mar 22, 2023

Discussed in the Nix team meeting 2023-03-17:

@peterbecich to answer your question from Discourse on behalf of the team (although I was not there, just inferring from the meeting notes): Yes, default behavior should stay the same. We could either have a --keep-going flag to delay the error, or alternatively a --current-system-only flag like suggested in #7759 (comment). Just have to make it consistent with --all-systems in nix flake show.

Currently nix flake check works fine without IFD, but breaks on most IFD flakes (because evaluates the outputs for all systems, which will break if there's no builder for all the systems).

There was no clear decision on the priority and how to proceed though, and I suppose we will talk about it again some time soon, and post an update again.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-17-nix-team-meeting-minutes-41/26614/1

@peterbecich
Copy link
Contributor Author

peterbecich commented Mar 26, 2023

@fricklerhandwerk okay, thank you. I will keep the default behavior and implement --current-system-only.

IMO --current-system-only is better than --keep-going with deferred error.

This will help nix flake check --current-system-only in GitHub Actions. If there is a deferred error code thrown by nix flake check --keep-going, the GitHub Action will fail.


Just have to make it consistent with --all-systems in nix flake show.

To make it consistent with nix flake show, it needs to change the default behavior.

If I'm not mistaken:

  • default behavior of nix flake show is current system only
  • default behavior of nix flake check is all systems

The choice to change the default behavior got 9 upvotes: #7759 (comment)

I have no opinion.

@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from 15d7393 to 581084d Compare March 26, 2023 19:28
@github-actions github-actions bot added the with-tests Issues related to testing. PRs with tests have some priority label Mar 26, 2023
@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from 1e63fe3 to d00082f Compare March 26, 2023 20:19
@peterbecich
Copy link
Contributor Author

Here are tests;

default behavior maintained:

$ ./result/bin/nix flake check ~/haskell/libraries/purescript-bridge2                                                                                                1 
...
error: a 'aarch64-linux' with features {} is required to build '/nix/store/d0w4jfn7ldnr7j1xipfzp3rmk7mwwf1j-cabal2nix-example.drv', 
but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}

The --current-system-only flag:

$ ./result/bin/nix flake check --current-system-only ~/haskell/libraries/purescript-bridge2                                                                          warning: unknown flake output 'haskellFlakeProjectModules'
warning: The check omitted these incompatible systems:
warning: aarch64-darwin
warning: aarch64-linux
warning: armv5tel-linux
warning: armv6l-linux
warning: armv7l-linux
warning: i686-linux
warning: mipsel-linux
warning: powerpc64le-linux
warning: riscv64-linux
warning: x86_64-darwin

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-17-nix-team-meeting-minutes-41/26614/3

@thufschmitt thufschmitt self-assigned this Mar 27, 2023
@fricklerhandwerk
Copy link
Contributor

fricklerhandwerk commented Mar 27, 2023

Discussed in Nix team meeting:

@peterbecich we talked about this again and agree on changing the default behavior, and making --all-systems work exactly as in nix flake show. Thanks for your patience!

@thufschmitt will shepherd the PR to the finish line.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2023-03-27-nix-team-meeting-minutes-44/26759/1

@peterbecich
Copy link
Contributor Author

peterbecich commented Apr 6, 2023

Great, thank you. This last commit d00082f should be deleted. I have reverted that commit.

@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from d00082f to df8133f Compare April 29, 2023 01:33
@peterbecich
Copy link
Contributor Author

peterbecich commented Apr 29, 2023

The PR implements the behavior everyone has agreed to: #7759 (comment)

@peterbecich
Copy link
Contributor Author

Can this be merged? Thank you

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @peterbecich, this fell down the cracks. Just one small comment on the message that gets printed, but good otherwise.

src/nix/flake.cc Outdated Show resolved Hide resolved
@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from c3ebe84 to 96470b3 Compare May 22, 2023 17:23
`nix flake show` now skips derivations for foreign systems:
NixOS#6988

This commit borrows from that to implement the same behavior for `nix flake check`.

See "nix flake check breaks on IFD in multi-platform flake"
NixOS#4265
Flake with two systems intentionally fails with `nix flake check --all-systems`;
the same flake succeeds with `nix flake check`.

Previously, this flake intentionally failed with `nix flake check`.
…urrent-system-only` flag"

This reverts commit d00082f.
@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from 96470b3 to a395e48 Compare May 22, 2023 17:43
Co-authored-by: Théophane Hufschmitt <[email protected]>
@peterbecich peterbecich force-pushed the skip-nix-flake-check-for-incompatible-systems branch from a395e48 to 567cb9b Compare May 22, 2023 18:11
@peterbecich
Copy link
Contributor Author

peterbecich commented May 22, 2023

@thufschmitt , thank you, I have checked and made a small fix to your commit, looks good to me.

$ nix flake check ~/haskell/libraries/hackage-server
warning: unknown flake output 'haskellFlakeProjectModules'
trace: WARNING[haskell-flake]: Multiple haskell overlays are applied in arbitrary order.
warning: The check omitted these incompatible systems: aarch64-darwin, x86_64-darwin
Use '--all-systems' to check all.

@thufschmitt
Copy link
Member

Awesome, thanks

@thufschmitt thufschmitt merged commit a420ccc into NixOS:master May 23, 2023
@peterbecich peterbecich deleted the skip-nix-flake-check-for-incompatible-systems branch May 27, 2023 20:10
@peterbecich
Copy link
Contributor Author

peterbecich commented May 27, 2023

This PR did not fix nix flake check for multi-platform Flakes using IFD: #4265 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants