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

bitbox-bridge: add systemd service and udev rule for linux distributions #391415

Merged
merged 1 commit into from
Mar 22, 2025

Conversation

izelnakri
Copy link
Contributor

Things done

  • Add udev rule to enable computer <> device communication.
  • Add a systemd service.

In the next PR(not this one), I plan to create nixos module to introduce programs.bitbox-bridge.enable and services.bitbox-bridge.enable with few options. These changes in this PR I suspect is needed for all linux distributions other than NixOS that allows users to install bitbox-bridge via nix or home-manager.

  • Built on platform(s)

    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested basic functionality of all binary files (usually in ./result/bin/)

  • Fits CONTRIBUTING.md.

@github-actions github-actions bot added 6.topic: python 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: kernel The Linux kernel 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: vim 6.topic: nixos-container Imperative and declarative systemd-nspawn containers 6.topic: module system About "NixOS" module system internals 6.topic: systemd 6.topic: cuda Parallel computing platform and API 6.topic: vscode 6.topic: lib The Nixpkgs function library 6.topic: rocm 6.topic: julia 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 6.topic: dotnet Language: .NET 6.topic: nvidia Nvidia-specific issues and fixes 6.topic: teams Relating to team creation, updates, other management actions 8.has: documentation This PR adds or changes documentation 6.topic: policy discussion labels Mar 20, 2025
@izelnakri izelnakri force-pushed the package-bitbox-bridge branch from d0ba5fd to f8093d7 Compare March 20, 2025 00:38
@github-actions github-actions bot removed 6.topic: python 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: kernel The Linux kernel 8.has: changelog 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: vim 6.topic: nixos-container Imperative and declarative systemd-nspawn containers 6.topic: module system About "NixOS" module system internals labels Mar 20, 2025
@github-actions github-actions bot added 10.rebuild-darwin: 1 10.rebuild-darwin: 1-10 10.rebuild-linux: 1 10.rebuild-linux: 1-10 and removed 6.topic: nvidia Nvidia-specific issues and fixes 6.topic: teams Relating to team creation, updates, other management actions labels Mar 20, 2025
@nix-owners nix-owners bot requested a review from tensor5 March 20, 2025 00:46
@izelnakri
Copy link
Contributor Author

@SuperSandro2000 @HeitorAugustoLN @ethancedwards8 @JohnRTitor This PR is ready for a review, afterwards I plan to create another PR where I'll add services.bitbox-bridge functionality for:

  • services.bitbox-bridge.enable
  • services.bitbox-bridge.port
  • services.bitbox-bridge.runOnMount

Thus I appreciate if we could review/merge this PR as early as possible, at your convenience ;)

@@ -34,6 +34,13 @@ rustPlatform.buildRustPackage (finalAttrs: {
libudev-zero
];

postInstall = lib.optionals stdenv.hostPlatform.isLinux ''
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
postInstall = lib.optionals stdenv.hostPlatform.isLinux ''
postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@HeitorAugustoLN changes made, thanks for pointing it out! ;)

@izelnakri izelnakri force-pushed the package-bitbox-bridge branch from f8093d7 to 9ab4423 Compare March 20, 2025 20:35
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Mar 20, 2025
@izelnakri izelnakri force-pushed the package-bitbox-bridge branch from 9ab4423 to d5b0ef3 Compare March 20, 2025 20:40
@github-actions github-actions bot added 10.rebuild-linux: 1 and removed 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-linux: 1 labels Mar 20, 2025
@@ -34,6 +34,13 @@ rustPlatform.buildRustPackage (finalAttrs: {
libudev-zero
];

postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
mkdir -p $out/lib/systemd/user
substitute ${./bitbox-bridge.service} $out/lib/systemd/user/bitbox-bridge.service \
Copy link
Contributor

Choose a reason for hiding this comment

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

Installing systemd service manually is a bad idea. Please use the module system. systemd.user.services suboptions should be what you are looking for.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option would be is to use the upstream systemd service file and patch it during postPatch.

https://github.com/BitBoxSwiss/bitbox-bridge/blob/63385207a0fb37f9bd7f0ff351214981a9b76d75/bitbox-bridge/release/linux/bitbox-bridge.service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Installing systemd service manually is a bad idea. Please use the module system. systemd.user.services suboptions should be what you are looking for.

I'm planning to do this as I mentioned in a separate PR. This PR adds this functionality for the ones who don't use NixOS. What would be your specific solution for implementing this functionality with systemd.user.services for people who don't use NixOS(archlinux with home-manager or MacOS etc.) How would that solution look like specifically?

Copy link
Contributor

Choose a reason for hiding this comment

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

This PR adds this functionality for the ones who don't use NixOS

I suppose you are right, but instead of having the same copy in two places, we can just copy the upstream one at install time, see below.

mkdir -p $out/lib/systemd/user
substitute ${./bitbox-bridge.service} $out/lib/systemd/user/bitbox-bridge.service \
--subst-var-by bitbox-bridge $out/bin/bitbox-bridge
install -Dt $out/lib/udev/rules.d ${./rules.d}/*
Copy link
Contributor

@JohnRTitor JohnRTitor Mar 21, 2025

Choose a reason for hiding this comment

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

De we have to maintain the udev rules ourselves, on Nixpkgs? Does upstream not provide these in their repo?

EDIT: Looks like we can copy these from the src. https://github.com/BitBoxSwiss/bitbox-bridge/blob/63385207a0fb37f9bd7f0ff351214981a9b76d75/bitbox-bridge/release/linux/hid-digitalbitbox.rules

Copy link
Contributor Author

@izelnakri izelnakri Mar 21, 2025

Choose a reason for hiding this comment

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

I wasn't sure how to copy it from the src in nix. What would be the specific reference in nix for the .rules file here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JohnRTitor done, thanks for the reference!

@izelnakri izelnakri force-pushed the package-bitbox-bridge branch from d5b0ef3 to d20f551 Compare March 22, 2025 14:20
postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
mkdir -p $out/lib/systemd/user
substitute ${src}/bitbox-bridge/release/linux/bitbox-bridge.service $out/lib/systemd/user/bitbox-bridge.service \
--replace /opt/bitbox-bridge/bin/bitbox-bridge $out/bin/bitbox-bridge
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
--replace /opt/bitbox-bridge/bin/bitbox-bridge $out/bin/bitbox-bridge
--replace-fail /opt/bitbox-bridge/bin/bitbox-bridge $out/bin/bitbox-bridge

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ;)

Comment on lines 39 to 41
substitute ${src}/bitbox-bridge/release/linux/bitbox-bridge.service $out/lib/systemd/user/bitbox-bridge.service \
--replace-fail /opt/bitbox-bridge/bin/bitbox-bridge $out/bin/bitbox-bridge
install -Dm644 ${src}/bitbox-bridge/release/linux/hid-digitalbitbox.rules $out/lib/udev/rules.d/50-hid-digitalbitbox.rules
Copy link
Member

Choose a reason for hiding this comment

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

Why not just this instead?

Suggested change
substitute ${src}/bitbox-bridge/release/linux/bitbox-bridge.service $out/lib/systemd/user/bitbox-bridge.service \
--replace-fail /opt/bitbox-bridge/bin/bitbox-bridge $out/bin/bitbox-bridge
install -Dm644 ${src}/bitbox-bridge/release/linux/hid-digitalbitbox.rules $out/lib/udev/rules.d/50-hid-digitalbitbox.rules
substitute bitbox-bridge/release/linux/bitbox-bridge.service $out/lib/systemd/user/bitbox-bridge.service \
--replace-fail /opt/bitbox-bridge/bin/bitbox-bridge $out/bin/bitbox-bridge
install -Dm644 bitbox-bridge/release/linux/hid-digitalbitbox.rules $out/lib/udev/rules.d/50-hid-digitalbitbox.rules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh ok I'll try this then we might be able to remove the rec as well

@@ -7,7 +7,7 @@
libudev-zero,
}:

rustPlatform.buildRustPackage (finalAttrs: {
rustPlatform.buildRustPackage (finalAttrs: rec {
Copy link
Member

Choose a reason for hiding this comment

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

There is no need for rec while using finalAttrs

Suggested change
rustPlatform.buildRustPackage (finalAttrs: rec {
rustPlatform.buildRustPackage (finalAttrs: {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, the rec is required for the src reference below.

Copy link
Member

Choose a reason for hiding this comment

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

finalAttrs.src does the same, and it is also not needed, you can operate on the $src directly without needing to reference its derivation

@izelnakri izelnakri force-pushed the package-bitbox-bridge branch from f1c281e to da388d3 Compare March 22, 2025 18:36
@JohnRTitor
Copy link
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 391415


x86_64-linux

✅ 1 package built:
  • bitbox-bridge

@JohnRTitor JohnRTitor merged commit 593a86b into NixOS:master Mar 22, 2025
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants