Skip to content

Commit

Permalink
website: extract 'donate' module
Browse files Browse the repository at this point in the history
  • Loading branch information
erikarvstedt committed Nov 19, 2021
1 parent 4a424c5 commit 2e74219
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 29 deletions.
5 changes: 4 additions & 1 deletion configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ services = {
};
services.joinmarket-ob-watcher.enable = true;

nix-bitcoin-org.website.enable = true;
nix-bitcoin-org.website = {
enable = true;
donate.btcpayserverAppId = "4D1Dxb5cGnXHRgNRBpoaraZKTX3i";
};

services.backups.enable = true;
};
Expand Down
4 changes: 4 additions & 0 deletions test/btcpayserver-config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ let
psql = "${config.services.postgresql.package}/bin/psql";
in
{
nix-bitcoin-org.website.donate = {
btcpayserverAppId = lib.mkForce "qJ1NExmDYQLr6MoyZFypeeFgLNj";
};

systemd.services.importBtcpayserverConfig = rec {
requires = [ "postgresql.service" ];
after = requires;
Expand Down
3 changes: 3 additions & 0 deletions test/scenarios.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rec {
../configuration.nix
scenarios.regtestBase
disableFeatures
./btcpayserver-config
];

# Improve eval performance by reusing pkgs
Expand Down Expand Up @@ -112,6 +113,8 @@ rec {
nix-bitcoin-org.website.enable = mkForce true;
services.clightning.enable = mkForce true;
services.btcpayserver.enable = mkForce true;
# Required for btcpayserver currency rate fetching
test.container.enableWAN = true;
};

# To demonstrate failures in the test runner
Expand Down
49 changes: 21 additions & 28 deletions website/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ let
options = {
nix-bitcoin-org.website = {
enable = mkEnableOption "nix-bitcoin.org website";
nginxHostConfig = mkOption {
type = types.lines;
default = "";
};
};
};

Expand All @@ -16,10 +20,10 @@ let
"localhost";

serviceAddress = service:
with config.services.${service};
"${address}:${toString port}";

with config.services.${service}; "${address}:${toString port}";
in {
imports = [ ./donate ];

inherit options;

config = mkIf cfg.enable (mkMerge [
Expand All @@ -41,32 +45,21 @@ in {

services.btcpayserver.rootpath = "btcpayserver";

nix-bitcoin-org.website.nginxHostConfig = mkBefore ''
root /var/www;
add_header Onion-Location http://qvzlxbjvyrhvsuyzz5t63xx7x336dowdvt7wfj53sisuun4i4rdtbzid.onion$request_uri;
location /obwatcher/ {
proxy_pass http://${serviceAddress "joinmarket-ob-watcher"};
rewrite /obwatcher/(.*) /$1 break;
}
'';

services.nginx = let
hostConfig = {
extraConfig = ''
root /var/www;
location /btcpayserver/ {
proxy_pass http://${serviceAddress "btcpayserver"};
}
# Disallow access to the btcpayserver admin interface and the API
location ~* ^/btcpayserver/(login|register|account|api|)(?:$|/) {
return 404;
}
location = /donate {
rewrite /donate /btcpayserver/apps/4D1Dxb5cGnXHRgNRBpoaraZKTX3i/pos;
}
location /obwatcher/ {
proxy_pass http://${serviceAddress "joinmarket-ob-watcher"};
rewrite /obwatcher/(.*) /$1 break;
}
add_header Onion-Location http://qvzlxbjvyrhvsuyzz5t63xx7x336dowdvt7wfj53sisuun4i4rdtbzid.onion$request_uri;
'';
};
hostConfig.extraConfig = ''
include ${pkgs.writeText "common.conf" cfg.nginxHostConfig};
'';
in {
enable = true;
enableReload = true;
Expand Down
35 changes: 35 additions & 0 deletions website/donate/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ config, lib, pkgs, ... }:

with lib;
let
options = {
nix-bitcoin-org.website.donate = {
btcpayserverAppId = mkOption {
type = types.str;
};
};
};

cfg = config.nix-bitcoin-org.website.donate;

btcpayserverAddress = with config.services.btcpayserver; "${address}:${toString port}";
in {
inherit options;

config = {
nix-bitcoin-org.website.nginxHostConfig = ''
location = /donate {
rewrite /donate /btcpayserver/apps/${cfg.btcpayserverAppId}/pos;
}
location /btcpayserver/ {
proxy_pass http://${btcpayserverAddress};
# Disallow access to the btcpayserver admin interface and the API
location ~* ^/btcpayserver/(login|register|account|api|)(?:$|/) {
return 404;
}
}
'';
};
}

0 comments on commit 2e74219

Please sign in to comment.