2018-12-01 09:26:29 -08:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.nanopos;
|
2019-11-27 05:04:23 -08:00
|
|
|
inherit (config) nix-bitcoin-services;
|
2018-12-01 09:26:29 -08:00
|
|
|
defaultItemsFile = pkgs.writeText "items.yaml" ''
|
|
|
|
tea:
|
|
|
|
price: 0.02 # denominated in the currency specified by --currency
|
|
|
|
title: Green Tea # title is optional, defaults to the key
|
|
|
|
|
|
|
|
coffee:
|
|
|
|
price: 1
|
|
|
|
|
|
|
|
bamba:
|
|
|
|
price: 3
|
|
|
|
|
|
|
|
beer:
|
|
|
|
price: 7
|
|
|
|
|
|
|
|
hat:
|
|
|
|
price: 15
|
|
|
|
|
|
|
|
tshirt:
|
|
|
|
price: 25
|
|
|
|
'';
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.services.nanopos = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, the nanopos service will be installed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
port = mkOption {
|
2020-06-02 08:09:52 -07:00
|
|
|
type = types.port;
|
2018-12-01 09:26:29 -08:00
|
|
|
default = 9116;
|
|
|
|
description = ''
|
|
|
|
"The port on which to listen for connections.";
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
itemsFile = mkOption {
|
|
|
|
type = types.path;
|
|
|
|
default = defaultItemsFile;
|
|
|
|
description = ''
|
|
|
|
"The items file (see nanopos README).";
|
|
|
|
'';
|
|
|
|
};
|
2020-06-10 07:44:50 -07:00
|
|
|
charged-url = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "http://localhost:9112";
|
|
|
|
description = ''
|
|
|
|
"The lightning charge server url.";
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
description = ''
|
|
|
|
"http server listen address.";
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = types.separatedString " ";
|
|
|
|
default = "";
|
|
|
|
description = "Extra command line arguments passed to nanopos.";
|
|
|
|
};
|
|
|
|
enforceTor = nix-bitcoin-services.enforceTor;
|
2018-12-01 09:26:29 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-06-15 03:34:11 -07:00
|
|
|
assertions = [
|
|
|
|
{ assertion = config.services.lightning-charge.enable;
|
|
|
|
message = "nanopos requires lightning-charge.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-04-07 13:47:45 -07:00
|
|
|
environment.systemPackages = [ pkgs.nix-bitcoin.nanopos ];
|
2020-06-10 07:44:50 -07:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."_" = {
|
|
|
|
root = "/var/www";
|
|
|
|
extraConfig = ''
|
|
|
|
location /store/ {
|
|
|
|
proxy_pass http://${toString cfg.host}:${toString cfg.port};
|
|
|
|
rewrite /store/(.*) /$1 break;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-01-02 07:17:57 -08:00
|
|
|
systemd.services.nanopos = {
|
|
|
|
description = "Run nanopos";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
requires = [ "lightning-charge.service" ];
|
|
|
|
after = [ "lightning-charge.service" ];
|
2020-05-05 06:18:41 -07:00
|
|
|
serviceConfig = nix-bitcoin-services.defaultHardening // {
|
2020-01-12 11:52:39 -08:00
|
|
|
EnvironmentFile = "${config.nix-bitcoin.secretsDir}/nanopos-env";
|
2020-06-10 07:44:50 -07:00
|
|
|
ExecStart = "${pkgs.nix-bitcoin.nanopos}/bin/nanopos -y ${cfg.itemsFile} -i ${toString cfg.host} -p ${toString cfg.port} -c ${toString cfg.charged-url} --show-bolt11 ${cfg.extraArgs}";
|
2019-01-02 07:17:57 -08:00
|
|
|
User = "nanopos";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2020-06-10 07:44:50 -07:00
|
|
|
} // (if cfg.enforceTor
|
|
|
|
then nix-bitcoin-services.allowTor
|
|
|
|
else nix-bitcoin-services.allowAnyIP)
|
|
|
|
// nix-bitcoin-services.nodejs;
|
2018-12-01 09:26:29 -08:00
|
|
|
};
|
2020-01-12 11:52:37 -08:00
|
|
|
users.users.nanopos = {
|
|
|
|
description = "nanopos User";
|
|
|
|
group = "nanopos";
|
|
|
|
};
|
|
|
|
users.groups.nanopos = {};
|
2020-01-12 11:52:38 -08:00
|
|
|
nix-bitcoin.secrets.nanopos-env.user = "nanopos";
|
2019-01-02 07:17:57 -08:00
|
|
|
};
|
2018-12-01 09:26:29 -08:00
|
|
|
}
|