Skip to content

Make local udev rules higher prioritized#13059

Merged
edolstra merged 1 commit intoNixOS:masterfrom
abbradar:udev-local-priority
Feb 23, 2016
Merged

Make local udev rules higher prioritized#13059
edolstra merged 1 commit intoNixOS:masterfrom
abbradar:udev-local-priority

Conversation

@abbradar
Copy link
Copy Markdown
Member

@abbradar abbradar commented Feb 17, 2016

I've spent some time debugging why wouldn't my udev rule work until I noticed that the rules won't apply because some other ones later override them. I wouldn't expect that user-defined rules would be overridden by anything. This could be changed by naming rules' files 99-local.{rules,hwdb} which I did and it fixed my issue. I don't have good knowledge of udev so this might not actually be a good idea. cc @edolstra as one who reviewed my udev changes before.

EDIT: added some sense -- I shouldn't make PRs laaate in the night ^^".

@abbradar abbradar added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 9.needs: reporter feedback This issue needs the person who filed it to respond labels Feb 17, 2016
@mention-bot
Copy link
Copy Markdown

By analyzing the blame information on this pull request, we identified @edolstra, @urkud and @aszlig to be potential reviewers

@abbradar
Copy link
Copy Markdown
Member Author

I've just noticed that #10646 was caused by this, too.

@domenkozar
Copy link
Copy Markdown
Member

@ctheune could this also be the reason for your problems in #12833 ?

@ctheune
Copy link
Copy Markdown
Contributor

ctheune commented Feb 17, 2016

Thanks for the headsup, I'll check that, but I don't think so. @abbradar: did you get rules applied after a switch at all?

@abbradar
Copy link
Copy Markdown
Member Author

Yes, and it also doesn't look to me this would fix your problem. FWIW, I have thought that relative paths won't work in udev altogether (same as in systemd), and PATH is set not for PROGRAM calls, but for sh calls in PROGRAM, like:

PROGRAM="/bin/sh -c 'fc-get-disk-alias %k'"

@edolstra
Copy link
Copy Markdown
Member

This will actually make some rules lower priority, such as:

    # Name network interfaces after their MAC address.
    services.udev.extraRules =
      ''
        SUBSYSTEM!="net", GOTO="my_end"
        IMPORT{builtin}="net_id"
        KERNEL=="vnet*", GOTO="my_end"
        NAME=="", ENV{ID_NET_NAME_MAC}!="", NAME="$env{ID_NET_NAME_MAC}"
        LABEL="my_end"
      '';

Because of the NAME=="" guard, it won't execute since systemd's 80-net-setup-link.rules has

NAME=="", ENV{ID_NET_NAME}!="", NAME="$env{ID_NET_NAME}"

@abbradar
Copy link
Copy Markdown
Member Author

Hm, I see the problem. What do you think of replacing extraRules with extraPreRules and extraPostRules? This would prevent further confusion like mine and in #10646.

@abbradar abbradar force-pushed the udev-local-priority branch 2 times, most recently from 80e0714 to 88de910 Compare February 19, 2016 15:48
@abbradar
Copy link
Copy Markdown
Member Author

I went ahead and implemented the proposed idea. In this incarnation I remove udev.extraRules completely to prevent further confusion -- is this acceptable?

@abbradar abbradar changed the title Make local udev rules higher prioritized Split extraRules into extraPreRules and extraPostRules Feb 19, 2016
@abbradar abbradar changed the title Split extraRules into extraPreRules and extraPostRules Split udev.extraRules into extraPreRules and extraPostRules Feb 19, 2016
@cstrahan
Copy link
Copy Markdown
Contributor

I don't know enough about udev to check over this. However, I might suggest using nixos/modules/rename.nix so existing uses of udev.extraRules will work for some time.

@abbradar abbradar added this to the 16.03 milestone Feb 21, 2016
@abbradar abbradar self-assigned this Feb 21, 2016
@abbradar abbradar modified the milestone: 16.03 Feb 21, 2016
@abbradar
Copy link
Copy Markdown
Member Author

Yeah, indeed -- removing extraRules completely might be too harsh now. I've updated the patch.

I think this is good to go and should remove much of the confusion around udev rules not working, but I want @edolstra comment as someone who's more knowledgeable on udev. What do you think? tl;dr: this splits out extraRules option into two separate ones for pre- and post-rules -- I expect that people who know what they are doing would now have a place to write post-rules and people who just want some god-damned rule found for their device to work would try both options and get it working one way or another.

@abbradar abbradar force-pushed the udev-local-priority branch from 88de910 to 751483c Compare February 21, 2016 22:45
@edolstra
Copy link
Copy Markdown
Member

Another possibility is to do your original proposal, and simply document the changed semantics in the release notes. For instance, in the example I posted, the fix is pretty easy (just remove the NAME==... check).

@abbradar
Copy link
Copy Markdown
Member Author

Hm, well -- truth be told I haven't seen much udev rules, so if pre-rules are not that much of a common case (the only one I've seen is your example), I think leaving just one option is better. Okay, let's do this! I'll add corresponding entries to the changelog.

@abbradar abbradar force-pushed the udev-local-priority branch from 751483c to 934813e Compare February 23, 2016 12:12
@abbradar abbradar changed the title Split udev.extraRules into extraPreRules and extraPostRules Make local udev rules higher prioritized Feb 23, 2016
@abbradar
Copy link
Copy Markdown
Member Author

The original patch is back, I've also added a changelog entry for it. Should be good now -- I'll merge this in few days unless we discover any problems with this.

@abbradar abbradar force-pushed the udev-local-priority branch from 934813e to 32df5ed Compare February 23, 2016 12:17
edolstra added a commit that referenced this pull request Feb 23, 2016
Make local udev rules higher prioritized
@edolstra edolstra merged commit cacf2d0 into NixOS:master Feb 23, 2016
@happysalada happysalada mentioned this pull request Jul 19, 2021
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 9.needs: reporter feedback This issue needs the person who filed it to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants