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>
|
2020-06-10 07:44:50 -07:00
|
|
|
${optionalString config.services.nanopos.enable ''<p><h2><a href="store/">store</a></h2></p>''}
|
2018-12-06 03:39:54 -08:00
|
|
|
<p>
|
|
|
|
<h3>
|
|
|
|
lightning node: CLIGHTNING_ID
|
|
|
|
</h3>
|
|
|
|
</p>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
'';
|
|
|
|
createWebIndex = pkgs.writeText "make-index.sh" ''
|
|
|
|
set -e
|
|
|
|
cp ${indexFile} /var/www/index.html
|
2020-05-06 03:43:57 -07:00
|
|
|
chown -R nginx:nginx /var/www/
|
2018-12-06 03:39:54 -08:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2020-06-10 07:48:20 -07:00
|
|
|
host = mkOption {
|
|
|
|
type = types.str;
|
2020-08-21 13:36:02 -07:00
|
|
|
default = if config.nix-bitcoin.netns-isolation.enable then
|
|
|
|
config.nix-bitcoin.netns-isolation.netns.nginx.address
|
|
|
|
else
|
|
|
|
"localhost";
|
2020-06-10 07:48:20 -07:00
|
|
|
description = "HTTP server listen address.";
|
|
|
|
};
|
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 {
|
2020-06-15 03:34:11 -07:00
|
|
|
assertions = [
|
|
|
|
{ assertion = config.services.nanopos.enable;
|
|
|
|
message = "nix-bitcoin-webindex requires nanopos.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2020-05-06 03:43:57 -07:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d /var/www 0755 nginx nginx - -"
|
|
|
|
];
|
|
|
|
|
2018-12-06 03:39:54 -08:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."_" = {
|
|
|
|
root = "/var/www";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
services.tor.hiddenServices.nginx = {
|
|
|
|
map = [{
|
2020-06-10 07:48:20 -07:00
|
|
|
port = 80; toHost = cfg.host;
|
2018-12-06 03:39:54 -08:00
|
|
|
} {
|
2020-06-10 07:48:20 -07:00
|
|
|
port = 443; toHost = cfg.host;
|
2018-12-06 03:39:54 -08:00
|
|
|
}];
|
|
|
|
version = 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
# create-web-index
|
|
|
|
systemd.services.create-web-index = {
|
|
|
|
description = "Get node info";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-08-21 13:35:58 -07:00
|
|
|
path = with pkgs; [
|
2020-05-03 07:42:53 -07:00
|
|
|
config.programs.nodeinfo
|
2019-11-27 05:04:33 -08:00
|
|
|
jq
|
|
|
|
sudo
|
2020-08-21 13:35:58 -07:00
|
|
|
] ++ optional config.services.lnd.enable config.services.lnd.cli
|
|
|
|
++ optional config.services.clightning.enable config.services.clightning.cli;
|
2020-05-05 06:18:41 -07:00
|
|
|
serviceConfig = nix-bitcoin-services.defaultHardening // {
|
2018-12-06 03:39:54 -08:00
|
|
|
ExecStart="${pkgs.bash}/bin/bash ${createWebIndex}";
|
|
|
|
User = "root";
|
|
|
|
Type = "simple";
|
|
|
|
RemainAfterExit="yes";
|
|
|
|
Restart = "on-failure";
|
|
|
|
RestartSec = "10s";
|
2020-05-05 06:25:00 -07:00
|
|
|
PrivateNetwork = "true"; # This service needs no network access
|
2020-05-06 01:28:00 -07:00
|
|
|
PrivateUsers = "false";
|
2020-05-05 08:15:16 -07:00
|
|
|
ReadWritePaths = "/var/www";
|
2020-05-05 06:27:07 -07:00
|
|
|
CapabilityBoundingSet = "CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_SYS_ADMIN CAP_CHOWN CAP_FSETID CAP_SETFCAP CAP_DAC_OVERRIDE CAP_DAC_READ_SEARCH CAP_FOWNER CAP_IPC_OWNER";
|
2020-05-05 06:18:41 -07:00
|
|
|
} // (if cfg.enforceTor
|
2019-04-27 16:53:26 -07:00
|
|
|
then nix-bitcoin-services.allowTor
|
|
|
|
else nix-bitcoin-services.allowAnyIP
|
|
|
|
);
|
2018-12-06 03:39:54 -08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|