# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie # SPDX-License-Identifier: MIT # The NixOS module: the one thing a program using this library cannot # arrange for itself. # # A Stream Deck appears as `/dev/hidraw*`, root-owned and mode 0600. # Enumerating those needs no permission, since the list comes out of # `/sys/class/hidraw`, but opening one does -- so without a rule the # library finds the device, fails to open it, and answers # `error.AccessDenied`. That reads as broken hardware rather than as a # permissions problem, and is the most common way a first run goes # wrong. # # There is no service here and no package. This library is a library; # what it needs from the system is the rules below and nothing else. # # **The rules are generated, not written.** `src/udev.zig` turns the # device table in `StreamDeck.Type` into them and `zig build udev` # prints them; what follows is what it printed. A test in that file # reads this one and fails if they have parted company, so a model # added to the library and forgotten here breaks the build rather than # quietly becoming unreachable. Regenerate with: # # nix develop -c zig build udev # # and with `-Dudev-group=plugdev` for the other shape. # # **They go in a rules file of their own, not `services.udev.extraRules`.** # NixOS writes `extraRules` into `99-local.rules`, and `uaccess` only works # from a file that sorts before systemd's `73-seat-late.rules`: that is where # the builtin that turns the tag into an ACL runs. A tag added in # `99-local.rules` is set after the only thing that reads it has already # finished, so the device keeps mode 0600 with no ACL, and nothing reports an # error. `70-streamdeck.rules`, installed through `services.udev.packages`, # is early enough. { config, lib, pkgs, ... }: let cfg = config.hardware.streamdeck; in { options.hardware.streamdeck = { enable = lib.mkEnableOption "access to Stream Deck devices for local users"; group = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; example = "plugdev"; description = '' Give the devices to this group rather than to whoever is logged in at the seat. Null uses `uaccess`, which is what a desktop wants: logind hands the device to the user of the active session and takes it back when they log out, so nobody has to be added to a group and a remote session cannot reach the deck on somebody's desk. Name a group only for a machine with no seat, such as one running a daemon. ''; }; }; config = lib.mkIf cfg.enable { services.udev.packages = [ (pkgs.writeTextFile { name = "streamdeck-udev-rules"; destination = "/lib/udev/rules.d/70-streamdeck.rules"; text = if cfg.group == null then '' SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0fd9", TAG+="uaccess" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1b1c", ATTRS{idProduct}=="2b18", TAG+="uaccess" '' else '' SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0fd9", MODE="0660", GROUP="${cfg.group}" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1b1c", ATTRS{idProduct}=="2b18", MODE="0660", GROUP="${cfg.group}" ''; }) ]; }; }