Skip to content

Make platform checks throw BuildError like other failures#13278

Merged
Mic92 merged 1 commit intoNixOS:masterfrom
DeterminateSystems:gustavderdrache/system-builderror
May 27, 2025
Merged

Make platform checks throw BuildError like other failures#13278
Mic92 merged 1 commit intoNixOS:masterfrom
DeterminateSystems:gustavderdrache/system-builderror

Conversation

@gustavderdrache
Copy link
Contributor

Motivation

Some complex derivations can depend on multiple systems. In cases where these aren't already cached (or locally buildable), Nix throws an error indicating that a derivation cannot be built. However, this does not behave the same with respect to other build errors. This PR changes the error to throw BuildError, allowing Nix to report the dependency tree that led to the build error, if any.

In the examples below, needs-* depends on a derivation that fails for the various scenarios I've tested locally.

Mismatched system

Before:

$ nix build .#needs-system
error: a 'bogus' with features {} is required to build '/nix/store/1aj7zljmh3zwff9z0pcan940kghql87c-bad-system.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}

After:

$ nix build .#needs-system
error: Cannot build '/nix/store/1aj7zljmh3zwff9z0pcan940kghql87c-bad-system.drv'.
       Reason: required system or feature not available
       Required system: 'bogus' with features {}
       Current system: 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}
error: Cannot build '/nix/store/xw31yf7yldxk163858vb8n51j9zbwnz7-needs-system.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/9qralxw4zvb5s9cii2lv04l66nygr95r-needs-system

Missing required feature

Before:

$ nix build .#needs-feature
error: a 'x86_64-linux' with features {bogus} is required to build '/nix/store/cny1i79kcnj8cbzm17bzmnn6f74jl0rr-bad-feature.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}

After:

$ nix build .#needs-feature
error: Cannot build '/nix/store/cny1i79kcnj8cbzm17bzmnn6f74jl0rr-bad-feature.drv'.
       Reason: required system or feature not available
       Required system: 'x86_64-linux' with features {bogus}
       Current system: 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}
error: Cannot build '/nix/store/ki2sn6hb4mkv0sg6c676lllmzs2alzxd-needs-feature.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/q8mp4h0s6g0qq6z72kwidlp5a7m7a9qx-needs-feature

Rosetta not installed

(Note that I don't have a Mac to test on, but I've used --system passed to sudo nix build to generate this error.)

Before:

$ nix build .#mac-system
error: run `/usr/sbin/softwareupdate --install-rosetta` to enable your aarch64-darwin to run programs for x86_64-darwin

After:

$ nix build .#mac-system
error: Cannot build '/nix/store/2iq7bj3zgsggbn1q6vdn79fk1wiksldy-mac-system.drv'.
       Reason: required system or feature not available
       Required system: 'x86_64-darwin' with features {}
       Current system: 'aarch64-darwin' with features {benchmark, big-parallel, kvm, nixos-test, uid-range}
       Note: run `/usr/sbin/softwareupdate --install-rosetta` to run programs for x86_64-darwin

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
@Mic92 Mic92 merged commit f7c94cd into NixOS:master May 27, 2025
12 checks passed
@gustavderdrache gustavderdrache deleted the gustavderdrache/system-builderror branch May 27, 2025 14:58
@roberth roberth added backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backports created Does not require attention and can be filtered away labels Jul 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.28-maintenance Automatically creates a PR against the branch backport 2.29-maintenance Automatically creates a PR against the branch backports created Does not require attention and can be filtered away

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants