Skip to content

udevCheckHook: guard platform#409385

Merged
r-vdp merged 1 commit intoNixOS:masterfrom
LordGrimmauld:udev-check-platform
May 21, 2025
Merged

udevCheckHook: guard platform#409385
r-vdp merged 1 commit intoNixOS:masterfrom
LordGrimmauld:udev-check-platform

Conversation

@LordGrimmauld
Copy link
Contributor

@LordGrimmauld LordGrimmauld commented May 21, 2025

It is technically possible to guard all udevCheckHook usages behind lib.optionals (stdenv.hostPlatform.isLinux && lib.meta.availableOn stdenv.buildPlatform systemdMinimal).

However, doing this is hard to read, clunky, and hard to discover. Not doing such a guard would mean cross-compilation darwin -> linux breaks (or darwin itself breaks, without cross). The workaround here is to just accept any udev rules if they can't be properly checked.

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/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (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.

@LordGrimmauld LordGrimmauld requested a review from r-vdp May 21, 2025 11:54
@LordGrimmauld
Copy link
Contributor Author

follow-up to #407629

@LordGrimmauld
Copy link
Contributor Author

Hmm, the darwin ci really does not like this one...

@LordGrimmauld
Copy link
Contributor Author

LordGrimmauld commented May 21, 2025

(thanks to emily and Alyssa for sanity-checking this over on matrix)

@github-actions github-actions bot added 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. labels May 21, 2025
@LordGrimmauld LordGrimmauld mentioned this pull request May 21, 2025
13 tasks
@r-vdp
Copy link
Contributor

r-vdp commented May 21, 2025

Right, thanks for catching this! Let's get this in quickly.

I am wondering if there is a nicer way that avoids running a loop and invoking true for every udev file on darwin, but it's also not the worst solution.

I definitely prefer this over needing conditionals at every usage site.

@LordGrimmauld LordGrimmauld force-pushed the udev-check-platform branch from 8638c02 to 45322f0 Compare May 21, 2025 12:38
@LordGrimmauld
Copy link
Contributor Author

Alright, some tweaking.
I checked against #409344, forcing the condition to false to check that code path. Working as intended.

@LordGrimmauld LordGrimmauld force-pushed the udev-check-platform branch from 45322f0 to 5bcd5d7 Compare May 21, 2025 12:40
@LordGrimmauld
Copy link
Contributor Author

(this time i am not forgetting the git add before amend...)

It is technically possible to guard all udevCheckHook usages behind
`lib.optionals (lib.meta.availableOn stdenv.buildPlatform systemdMinimal)`.

However, doing this is hard to read, clunky, and hard to discover.
*Not* doing such a guard would mean cross-compilation darwin -> linux breaks.
The workaround here is to just accept any udev rules if they can't be properly checked.
@LordGrimmauld LordGrimmauld force-pushed the udev-check-platform branch from 5bcd5d7 to 1461a84 Compare May 21, 2025 13:07
@LordGrimmauld
Copy link
Contributor Author

Okay, now i think i am happy with this.

@github-actions github-actions bot added 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels May 21, 2025
@r-vdp r-vdp merged commit d9305c9 into NixOS:master May 21, 2025
18 of 21 checks passed
@LordGrimmauld
Copy link
Contributor Author

We probably also should backport the fix

@nixpkgs-ci
Copy link
Contributor

nixpkgs-ci bot commented May 21, 2025

Successfully created backport PR for release-25.05:

@nixpkgs-ci nixpkgs-ci bot added the 8.has: port to stable This PR already has a backport to the stable release. label May 21, 2025
# udev rules can only be checked if systemd (specifically, 'udevadm') can be executed on build platform
# if udev is not available on hostPlatform, there is no point in checking rules
applyHook =
lib.meta.availableOn stdenv.hostPlatform udev
Copy link
Member

Choose a reason for hiding this comment

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

If I add udevCheckHook to nativeInstallCheckInputs, wouldn't this hostPlatform be the build platform? So this would really need to check the targetPlatform? (But I'm not certain how the splicing logic works in this case...)

Copy link
Member

Choose a reason for hiding this comment

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

This would only be a concern for Linux → non-Linux cross, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lib.meta.availableOn stdenv.hostPlatform udev won't actually cause build failures if it doesn't check correctly. The only thing that is actually required for the hook to run is systemd being executable on buildPlatform.

Your concern is valid though. However:

nix-repl> pkgsCross.x86_64-darwin.stdenv.hostPlatform.config
"x86_64-apple-darwin"

nix-repl> lib.meta.availableOn pkgsCross.x86_64-darwin.stdenv.hostPlatform udev
false

nix-repl>

(executed on a x86-64-linux machine)
This has me believe the check does actually work correctly.

Copy link
Member

Choose a reason for hiding this comment

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

That is not the stdenv this package would receive, thanks to splicing.
Since it is a native input, it would be built using

buildPlatform = builder
hostPlatform = builder
targetPlatform = host

(relative to the package using the hook as a native input)

Copy link
Member

Choose a reason for hiding this comment

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

I suppose the easiest test would be Linux → BSD variant. I'll see if there is a setup that has a cached cross stdenv.

Copy link
Member

Choose a reason for hiding this comment

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

I see. But I don’t understand what the scripting thing has to do with the targetPlatform?

We should avoid using targetPlatform whenever we can.

Copy link
Member

Choose a reason for hiding this comment

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

The only reason we want targetPlatform here is because the hook is added to nativeInstallCheckInputs in a package X, but we would like to know whether udev is available on the hostPlatform for X.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, my point is that I don’t see why we care about udev being available on X’s host platform. There’s no harm in checking the files even if they won’t be used. If they’re included at all, they should be correct; if they shouldn’t be included because they won’t be used, then that’s a separate issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in that case that condition should then be dropped completely, only leaving the buildPlatform check to test whether the hook can actually run

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Emily has a point, i opened #412708 to just remove this check.

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

Labels

8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants