1 { config, lib, options, pkgs, ... }:
4 cfg = config.services.ergo;
5 opt = options.services.ergo;
7 inherit (lib) literalExpression mkEnableOption mkIf mkOption optionalString types;
9 configFile = pkgs.writeText "ergo.conf" (''
11 directory = "${cfg.dataDir}"
15 wallet.secretStorage.secretDir = "${cfg.dataDir}/wallet/keystore"
20 bindAddress = "${cfg.listen.ip}:${toString cfg.listen.port}"
22 '' + optionalString (cfg.api.keyHash != null) ''
24 apiKeyHash = "${cfg.api.keyHash}"
25 bindAddress = "${cfg.api.listen.ip}:${toString cfg.api.listen.port}"
36 enable = mkEnableOption "Ergo service";
40 default = "/var/lib/ergo";
41 description = "The data directory for the Ergo node.";
48 description = "IP address on which the Ergo node should listen.";
54 description = "Listen port for the Ergo node.";
60 type = types.nullOr types.str;
62 example = "324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf";
63 description = "Hex-encoded Blake2b256 hash of an API key as a 64-chars long Base16 string.";
70 description = "IP address that the Ergo node API should listen on if {option}`api.keyHash` is defined.";
76 description = "Listen port for the API endpoint if {option}`api.keyHash` is defined.";
84 description = "Connect to testnet network instead of the default mainnet.";
90 description = "The user as which to run the Ergo node.";
96 defaultText = literalExpression "config.${opt.user}";
97 description = "The group as which to run the Ergo node.";
100 openFirewall = mkOption {
103 description = "Open ports in the firewall for the Ergo node as well as the API.";
108 config = mkIf cfg.enable {
110 systemd.tmpfiles.rules = [
111 "d '${cfg.dataDir}' 0770 '${cfg.user}' '${cfg.group}' - -"
114 systemd.services.ergo = {
115 description = "ergo server";
116 wantedBy = [ "multi-user.target" ];
117 wants = [ "network-online.target" ];
118 after = [ "network-online.target" ];
122 ExecStart = ''${pkgs.ergo}/bin/ergo \
123 ${optionalString (!cfg.testnet)
129 networking.firewall = mkIf cfg.openFirewall {
130 allowedTCPPorts = [ cfg.listen.port ] ++ [ cfg.api.listen.port ];
133 users.users.${cfg.user} = {
136 description = "Ergo daemon user";
141 users.groups.${cfg.group} = {};