1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.trezord;
9in
10{
11
12 ### docs
13
14 meta = {
15 doc = ./trezord.md;
16 };
17
18 ### interface
19
20 options = {
21 services.trezord = {
22 enable = lib.mkOption {
23 type = lib.types.bool;
24 default = false;
25 description = ''
26 Enable Trezor bridge daemon, for use with Trezor hardware bitcoin wallets.
27 '';
28 };
29
30 emulator.enable = lib.mkOption {
31 type = lib.types.bool;
32 default = false;
33 description = ''
34 Enable Trezor emulator support.
35 '';
36 };
37
38 emulator.port = lib.mkOption {
39 type = lib.types.port;
40 default = 21324;
41 description = ''
42 Listening port for the Trezor emulator.
43 '';
44 };
45 };
46 };
47
48 ### implementation
49
50 config = lib.mkIf cfg.enable {
51 services.udev.packages = [ pkgs.trezor-udev-rules ];
52
53 systemd.services.trezord = {
54 description = "Trezor Bridge";
55 after = [ "network.target" ];
56 wantedBy = [ "multi-user.target" ];
57 path = [ ];
58 serviceConfig = {
59 Type = "simple";
60 ExecStart = "${pkgs.trezord}/bin/trezord-go ${lib.optionalString cfg.emulator.enable "-e ${builtins.toString cfg.emulator.port}"}";
61 User = "trezord";
62 };
63 };
64
65 users.users.trezord = {
66 group = "trezord";
67 description = "Trezor bridge daemon user";
68 isSystemUser = true;
69 };
70
71 users.groups.trezord = { };
72 };
73}