feat: nix flake to build this on nix.#2
Conversation
|
Fixes #1 |
|
Possible limitation: assumes pipewire and wireplumber are enabled since the service depends on it. Whether to force enable them in the default nixosModule or to just note this in documentation is an open topic. |
|
Hello, appreciate you taking interest in the project.
I think an assertion or a warning in the flake if pipewire/wireplumber is absent would be ideal. Then we could merge. |
|
Assertions added |
There was a problem hiding this comment.
Pull request overview
Adds Nix flake packaging and a NixOS module to build/install btd700ctl artifacts and integrate udev + systemd user service enablement, plus README documentation for Nix usage.
Changes:
- Introduce
flake.nixwith apackagesoutput andnixosModules.defaultfor NixOS integration. - Package udev rules and patch/wrap the
btd700dsystemd user service for Nix store paths. - Document Nix flake/module usage in
README.md.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| flake.nix | Defines a Nix package derivation, installs udev rules, patches/wraps btd700d, and adds a NixOS module intended to enable the user service. |
| README.md | Adds a Nix configuration snippet showing how to consume the flake’s NixOS module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| homepage = "https://github.com/sobalap/btd700ctl"; | ||
| license = licenses.lgpl21Only; | ||
| platforms = platforms.linux; | ||
| mainProgram = "btd700ctl"; |
There was a problem hiding this comment.
meta.mainProgram is set to "btd700ctl", but this project doesn't install an executable with that name (CMake installs btd700d and btd700_example). This will break nix run/nix bundle expectations; set mainProgram to an actually-installed binary or remove it.
| mainProgram = "btd700ctl"; | |
| mainProgram = "btd700d"; |
| buildInputs = with pkgs; [ hidapi ]; | ||
|
|
||
| postInstall = '' | ||
| install -Dm644 ../udev/99-btd700.rules -t $out/lib/udev/rules.d/ |
There was a problem hiding this comment.
install -Dm644 ... -t $out/lib/udev/rules.d/ relies on the destination directory already existing; with -t this is not guaranteed, so the build can fail on a clean $out. Install directly to the full destination path (or explicitly mkdir -p the directory) to ensure the directory is created.
| install -Dm644 ../udev/99-btd700.rules -t $out/lib/udev/rules.d/ | |
| install -Dm644 ../udev/99-btd700.rules $out/lib/udev/rules.d/99-btd700.rules |
| buildInputs = with pkgs; [ hidapi ]; | ||
|
|
||
| postInstall = '' | ||
| install -Dm644 ../udev/99-btd700.rules -t $out/lib/udev/rules.d/ |
There was a problem hiding this comment.
The udev rules source path ../udev/99-btd700.rules is tied to the CMake build directory layout (e.g., $sourceRoot/build). This is brittle and can break if the build directory changes; prefer referencing the source via $src/$sourceRoot (or ${./udev/99-btd700.rules}) so the path is stable.
| install -Dm644 ../udev/99-btd700.rules -t $out/lib/udev/rules.d/ | |
| install -Dm644 ${./udev/99-btd700.rules} -t $out/lib/udev/rules.d/ |
| systemd.user.services.btd700d = { | ||
| wantedBy = [ "default.target" ]; | ||
| enable = true; | ||
| }; |
There was a problem hiding this comment.
systemd.user.services.btd700d is enabled without defining serviceConfig.ExecStart/script (or another mechanism) to actually start the daemon. Unless NixOS is meant to enable a unit file provided by systemd.user.packages, this will produce an incomplete unit and fail to start. Either define the unit contents here (ExecStart pointing at ${pkg}/bin/btd700d) or install the packaged user unit via the appropriate systemd.user.packages/unit-enabling pattern.
| # nix | ||
| inputs = { | ||
| btd700ctl = { | ||
| url = "github:sobalap/btd700ctl"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| } | ||
|
|
||
| modules = [ | ||
| inputs.btd700ctl.nixosModules.default | ||
| ] | ||
|
|
There was a problem hiding this comment.
The new Nix configuration snippet is inside a ```bash code block and is not valid Nix as written (missing trailing semicolons like inputs = { ... }; / `modules = [ ... ];`). Move it to a dedicated `nix` (or untyped) fenced block and make the snippet syntactically correct so users can copy/paste it.
|
@dzuberi can you address these comments? I'm not particularly familiar with Nix, but they seem reasonable enough for me to care |
The flake creates and adds the package, automatically adds the udev rule, fixes the binary location for the systemd service, and enables the systemd service. It worked on my system.