summaryrefslogtreecommitdiff
path: root/modules/services/trezord.nix
blob: 8da05f34243c7ee1a7131226a662964afa4eb6ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.services.trezord;
in {
  # Options copied from:
  # https://github.com/NixOS/nixpkgs/blob/9d6e454b857fb472fa35fc8b098fa5ac307a0d7d/nixos/modules/services/hardware/trezord.nix#L16
  options = {
    services.trezord = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Enable Trezor bridge daemon, for use with Trezor hardware wallets.
        '';
      };

      emulator.enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Enable Trezor emulator support.
        '';
       };

      emulator.port = mkOption {
        type = types.port;
        default = 21324;
        description = ''
          Listening port for the Trezor emulator.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    launchd.user.agents.trezord = {
      serviceConfig = {
        ProgramArguments = [ "${pkgs.trezord}/bin/trezord-go" ]
          ++ optionals cfg.emulator.enable [ "-e" (builtins.toString cfg.emulator.port) ];
        KeepAlive = true;
        RunAtLoad = true;
      };
    };
  };
}