2018-12-06 03:39:54 -08:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2019-01-01 11:16:24 -08:00
|
|
|
cfg = config.services.nix-bitcoin-webindex;
|
2019-11-27 05:04:23 -08:00
|
|
|
inherit (config) nix-bitcoin-services;
|
2018-12-06 03:39:54 -08:00
|
|
|
indexFile = pkgs.writeText "index.html" ''
|
|
|
|
<html>
|
|
|
|
<body>
|
|
|
|
<p>
|
|
|
|
<h1>
|
|
|
|
nix-bitcoin
|
|
|
|
</h1>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<h2>
|
|
|
|
<a href="store/">store</a>
|
|
|
|
</h2>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<h3>
|
|
|
|
lightning node: CLIGHTNING_ID
|
|
|
|
</h3>
|
|
|
|
</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
'';
|
|
|
|
createWebIndex = pkgs.writeText "make-index.sh" ''
|
|
|
|
set -e
|
|
|
|
mkdir -p /var/www/
|
|
|
|
cp ${indexFile} /var/www/index.html
|
|
|
|
chown -R nginx /var/www/
|
|
|
|
nodeinfo
|
|
|
|
. <(nodeinfo)
|
|
|
|
sed -i "s/CLIGHTNING_ID/$CLIGHTNING_ID/g" /var/www/index.html
|
|
|
|
'';
|
|
|
|
in {
|
2019-01-01 11:16:24 -08:00
|
|
|
options.services.nix-bitcoin-webindex = {
|
2018-12-06 03:39:54 -08:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
If enabled, the webindex service will be installed.
|
|
|
|
'';
|
|
|
|
};
|
2019-04-27 16:53:26 -07:00
|
|
|
enforceTor = nix-bitcoin-services.enforceTor;
|
2018-12-06 03:39:54 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."_" = {
|
|
|
|
root = "/var/www";
|
|
|
|
extraConfig = ''
|
|
|
|
location /store/ {
|
|
|
|
proxy_pass http://127.0.0.1:${toString config.services.nanopos.port};
|
|
|
|
rewrite /store/(.*) /$1 break;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
services.tor.hiddenServices.nginx = {
|
|
|
|
map = [{
|
|
|
|
port = 80;
|
|
|
|
} {
|
|
|
|
port = 443;
|
|
|
|
}];
|
|
|
|
version = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
# create-web-index
|
|
|
|
systemd.services.create-web-index = {
|
|
|
|
description = "Get node info";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "nodeinfo.service" ];
|
2019-11-27 05:04:33 -08:00
|
|
|
path = with pkgs; [
|
|
|
|
nix-bitcoin.nodeinfo
|
|
|
|
config.services.clightning.cli
|
|
|
|
jq
|
|
|
|
sudo
|
|
|
|
];
|
2018-12-06 03:39:54 -08:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart="${pkgs.bash}/bin/bash ${createWebIndex}";
|
|
|
|
User = "root";
|
|
|
|
Type = "simple";
|
|
|
|
RemainAfterExit="yes";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2019-04-27 16:53:26 -07:00
|
|
|
} // nix-bitcoin-services.defaultHardening
|
|
|
|
// (if cfg.enforceTor
|
|
|
|
then nix-bitcoin-services.allowTor
|
|
|
|
else nix-bitcoin-services.allowAnyIP
|
|
|
|
);
|
2018-12-06 03:39:54 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|