diff --git a/modules/nixbitcoin-webindex.nix b/modules/nixbitcoin-webindex.nix new file mode 100644 index 0000000..00d5dc9 --- /dev/null +++ b/modules/nixbitcoin-webindex.nix @@ -0,0 +1,86 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.nixbitcoin-webindex; + indexFile = pkgs.writeText "index.html" '' + + +

+

+ nix-bitcoin +

+

+

+

+ store +

+

+

+

+ lightning node: CLIGHTNING_ID +

+

+ + + ''; + 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 { + options.services.nixbitcoin-webindex = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + If enabled, the webindex service will be installed. + ''; + }; + }; + + 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" ]; + path = [ pkgs.nodeinfo pkgs.clightning pkgs.jq pkgs.sudo ]; + serviceConfig = { + ExecStart="${pkgs.bash}/bin/bash ${createWebIndex}"; + User = "root"; + Type = "simple"; + RemainAfterExit="yes"; + Restart = "on-failure"; + RestartSec = "10s"; + }; + }; + }; +}