10 cfg = config.services.ergo;
11 opt = options.services.ergo;
22 configFile = pkgs.writeText "ergo.conf" (
25 directory = "${cfg.dataDir}"
29 wallet.secretStorage.secretDir = "${cfg.dataDir}/wallet/keystore"
34 bindAddress = "${cfg.listen.ip}:${toString cfg.listen.port}"
37 + optionalString (cfg.api.keyHash != null) ''
39 apiKeyHash = "${cfg.api.keyHash}"
40 bindAddress = "${cfg.api.listen.ip}:${toString cfg.api.listen.port}"
54 enable = mkEnableOption "Ergo service";
58 default = "/var/lib/ergo";
59 description = "The data directory for the Ergo node.";
66 description = "IP address on which the Ergo node should listen.";
72 description = "Listen port for the Ergo node.";
78 type = types.nullOr types.str;
80 example = "324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf";
81 description = "Hex-encoded Blake2b256 hash of an API key as a 64-chars long Base16 string.";
88 description = "IP address that the Ergo node API should listen on if {option}`api.keyHash` is defined.";
94 description = "Listen port for the API endpoint if {option}`api.keyHash` is defined.";
102 description = "Connect to testnet network instead of the default mainnet.";
108 description = "The user as which to run the Ergo node.";
114 defaultText = literalExpression "config.${opt.user}";
115 description = "The group as which to run the Ergo node.";
118 openFirewall = mkOption {
121 description = "Open ports in the firewall for the Ergo node as well as the API.";
126 config = mkIf cfg.enable {
128 systemd.tmpfiles.rules = [
129 "d '${cfg.dataDir}' 0770 '${cfg.user}' '${cfg.group}' - -"
132 systemd.services.ergo = {
133 description = "ergo server";
134 wantedBy = [ "multi-user.target" ];
135 wants = [ "network-online.target" ];
136 after = [ "network-online.target" ];
141 ${pkgs.ergo}/bin/ergo \
142 ${optionalString (!cfg.testnet) "--mainnet"} \
147 networking.firewall = mkIf cfg.openFirewall {
148 allowedTCPPorts = [ cfg.listen.port ] ++ [ cfg.api.listen.port ];
151 users.users.${cfg.user} = {
154 description = "Ergo daemon user";
159 users.groups.${cfg.group} = { };