move mkHiddenService to lib

This commit is contained in:
Erik Arvstedt 2021-02-03 22:44:42 +01:00 committed by nixbitcoin
parent a26ed03d77
commit a344ae95c9
No known key found for this signature in database
GPG Key ID: DD11F9AD5308B3BA
3 changed files with 12 additions and 14 deletions

View File

@ -10,6 +10,7 @@ with lib;
let let
cfg = config.nix-bitcoin.onionServices; cfg = config.nix-bitcoin.onionServices;
nbLib = config.nix-bitcoin.lib;
services = builtins.attrNames cfg; services = builtins.attrNames cfg;
@ -60,13 +61,10 @@ in {
let let
service = config.services.${name}; service = config.services.${name};
inherit (cfg.${name}) externalPort; inherit (cfg.${name}) externalPort;
in { in nbLib.mkHiddenService {
map = [{ port = if externalPort != null then externalPort else service.port;
port = if externalPort != null then externalPort else service.port; toPort = service.port;
toPort = service.port; toHost = if service.address == "0.0.0.0" then "127.0.0.1" else service.address;
toHost = if service.address == "0.0.0.0" then "127.0.0.1" else service.address;
}];
version = 3;
} }
); );
}; };

View File

@ -4,13 +4,8 @@ with lib;
let let
cfg = config.services; cfg = config.services;
nbLib = config.nix-bitcoin.lib;
operatorName = config.nix-bitcoin.operator.name; operatorName = config.nix-bitcoin.operator.name;
mkHiddenService = map: {
map = [ map ];
version = 3;
};
in { in {
imports = [ imports = [
../modules.nix ../modules.nix
@ -30,7 +25,7 @@ in {
]; ];
# sshd # sshd
services.tor.hiddenServices.sshd = mkHiddenService { port = 22; }; services.tor.hiddenServices.sshd = nbLib.mkHiddenService { port = 22; };
nix-bitcoin.onionAddresses.access.${operatorName} = [ "sshd" ]; nix-bitcoin.onionAddresses.access.${operatorName} = [ "sshd" ];
services.bitcoind = { services.bitcoind = {

View File

@ -65,4 +65,9 @@ let self = {
type = types.str; type = types.str;
default = "exec"; default = "exec";
}; };
mkHiddenService = map: {
map = [ map ];
version = 3;
};
}; in self }; in self