1{ config, lib, pkgs, ... }:
2
3with lib;
4let
5 cfg = config.services.trezord;
6in {
7
8 ### interface
9
10 options = {
11 services.trezord = {
12 enable = mkOption {
13 type = types.bool;
14 default = false;
15 description = ''
16 Enable Trezor bridge daemon, for use with Trezor hardware bitcoin wallets.
17 '';
18 };
19 };
20 };
21
22 ### implementation
23
24 config = mkIf cfg.enable {
25 services.udev.packages = lib.singleton (pkgs.writeTextFile {
26 name = "trezord-udev-rules";
27 destination = "/etc/udev/rules.d/51-trezor.rules";
28 text = ''
29 SUBSYSTEM=="usb", ATTR{idVendor}=="534c", ATTR{idProduct}=="0001", MODE="0666", GROUP="dialout", SYMLINK+="trezor%n"
30 KERNEL=="hidraw*", ATTRS{idVendor}=="534c", ATTRS{idProduct}=="0001", MODE="0666", GROUP="dialout"
31 '';
32 });
33
34 systemd.services.trezord = {
35 description = "TREZOR Bridge";
36 after = [ "systemd-udev-settle.service" "network.target" ];
37 wantedBy = [ "multi-user.target" ];
38 path = [];
39 serviceConfig = {
40 Type = "simple";
41 ExecStart = "${pkgs.trezord}/bin/trezord -f";
42 User = "trezord";
43 };
44 };
45
46 users.users.trezord = {
47 group = "trezord";
48 description = "Trezor bridge daemon user";
49 };
50
51 users.groups.trezord = {};
52 };
53}
54