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

Add udev rules for Ledger devices #39950

Closed
wants to merge 2 commits into from

Conversation

chris-martin
Copy link
Contributor

@chris-martin chris-martin commented May 3, 2018

This adds udev rules for Ledget wallets, allowing you to use a Ledger device by adding hardware.ledger.enable = true; to your NixOS config.

The source file is a bash script at https://github.com/LedgerHQ/udev-rules/blob/master/add_udev_rules.sh and I made the ledger-udev-rule package by applying some replacements with sed. The rules file ends up looks like this:

lib/udev/rules.d/20-ledger.rules

SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="1b7c",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="2b7c",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="3b7c",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="4b7c",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="1807",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2581", ATTRS{idProduct}=="1808",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0000",  TAG+="uaccess"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0001",  TAG+="uaccess"

</listitem>
<listitem>
<para>
<literal>./services/hardware/ledger.nix</literal>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this section is usually auto-generated before release.


installPhase = ''
mkdir --parents "$out/lib/udev/rules.d"
cat add_udev_rules.sh | grep echo | sed "s_/etc_$out/lib_" | sed "s_hw1_ledger_" | sed 's_MODE=\\"0660\\",__' | sed 's_GROUP=\\"plugdev\\"_TAG+=\\"uaccess\\"_' > install.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you maybe ask upstream to provide the rules in a separate file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Submitted LedgerHQ/udev-rules#1 upstream.

Copy link
Member

Choose a reason for hiding this comment

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

Could we just embed these rules? The other key modules does it as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did it this way because I was trying to follow the example of an existing package (libu2f-host), but I don't have an opinion. I'd be happy to amend the PR to embed the rules if that's preferable.

Copy link
Contributor

@jtojnar jtojnar May 4, 2018

Choose a reason for hiding this comment

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

I think the script is preferable – since upstream does not provide the rules file, we would need to convert the add_udev_rules.sh file with each update anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I doubt that script is likely to be stable enough for my sed nonsense to remain reliable, so I think it's a wash.

Copy link
Contributor

Choose a reason for hiding this comment

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

It got merged!

@CMCDragonkai
Copy link
Member

For some reason, trying out your rules on my NixOS doesn't work. It only works if I explicitly set OWNER="cmcdragonkai". I monitor the udevadm, and it shows that it adds the device, and everything else is correct, but the Ledger Manager is just stuck. If I add the owner rule, everything just works.

Is there something that's meant to happen with uaccess that requires a prompt or something? I'm not running a normal DE, I'm running XMonad if that helps.

@CMCDragonkai
Copy link
Member

Should we add udev-acl as well?

@rehno-lindeque
Copy link
Contributor

Should we add udev-acl as well?

I don't think so, I believe udev-acl doesn't exist anymore.

@rehno-lindeque
Copy link
Contributor

For some reason, trying out your rules on my NixOS doesn't work. It only works if I explicitly set OWNER="cmcdragonkai".

Possibly getfacl /dev/hidraw* could help debug. (Should be able to see user:cmcdragonkai:rw-?)

@asymmetric
Copy link
Contributor

asymmetric commented Feb 10, 2019

@CMCDragonkai's addition was necessary for this to work in my case too, and I use i3. @chris-martin maybe OWNER should be added in this module?


EDIT: The uaccess tag only works if the rule is sourced in a file with id < 73, so that explains why it wasn't working when added to extraRules (which appends to a 99- file).

@asymmetric asymmetric mentioned this pull request Feb 14, 2019
10 tasks
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.

None yet

6 participants