services: add helper fn setAllowedIPAddresses
Also use 'allowLocalIPAddresses' instead of 'allowTor' in bitcoind-import-banlist which doesn't use Tor.
This commit is contained in:
parent
cdf27d9d0c
commit
020433cec6
|
@ -357,9 +357,7 @@ in {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
UMask = mkIf cfg.dataDirReadableByGroup "0027";
|
UMask = mkIf cfg.dataDirReadableByGroup "0027";
|
||||||
ReadWritePaths = cfg.dataDir;
|
ReadWritePaths = cfg.dataDir;
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP)
|
|
||||||
// optionalAttrs (cfg.zmqpubrawblock != null || cfg.zmqpubrawtx != null) nbLib.allowAnyProtocol;
|
// optionalAttrs (cfg.zmqpubrawblock != null || cfg.zmqpubrawtx != null) nbLib.allowAnyProtocol;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -385,7 +383,7 @@ in {
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
Group = cfg.group;
|
Group = cfg.group;
|
||||||
ReadWritePaths = cfg.dataDir;
|
ReadWritePaths = cfg.dataDir;
|
||||||
} // nbLib.allowTor;
|
} // nbLib.allowLocalIPAddresses;
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.${cfg.user}.group = cfg.group;
|
users.users.${cfg.user}.group = cfg.group;
|
||||||
|
|
|
@ -155,10 +155,7 @@ in {
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
ReadWritePaths = cfg.nbxplorer.dataDir;
|
ReadWritePaths = cfg.nbxplorer.dataDir;
|
||||||
MemoryDenyWriteExecute = "false";
|
MemoryDenyWriteExecute = "false";
|
||||||
} // (if cfg.nbxplorer.enforceTor
|
} // nbLib.allowedIPAddresses cfg.nbxplorer.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.btcpayserver = let
|
systemd.services.btcpayserver = let
|
||||||
|
@ -204,10 +201,7 @@ in {
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
ReadWritePaths = cfg.btcpayserver.dataDir;
|
ReadWritePaths = cfg.btcpayserver.dataDir;
|
||||||
MemoryDenyWriteExecute = "false";
|
MemoryDenyWriteExecute = "false";
|
||||||
} // (if cfg.btcpayserver.enforceTor
|
} // nbLib.allowedIPAddresses cfg.btcpayserver.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP
|
|
||||||
);
|
|
||||||
}; in self;
|
}; in self;
|
||||||
|
|
||||||
users.users.${cfg.nbxplorer.user} = {
|
users.users.${cfg.nbxplorer.user} = {
|
||||||
|
|
|
@ -128,10 +128,7 @@ in {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
ReadWritePaths = cfg.dataDir;
|
ReadWritePaths = cfg.dataDir;
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP
|
|
||||||
);
|
|
||||||
# Wait until the rpc socket appears
|
# Wait until the rpc socket appears
|
||||||
postStart = ''
|
postStart = ''
|
||||||
while [[ ! -e ${cfg.networkDir}/lightning-rpc ]]; do
|
while [[ ! -e ${cfg.networkDir}/lightning-rpc ]]; do
|
||||||
|
|
|
@ -102,10 +102,7 @@ in {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
ReadWritePaths = "${cfg.dataDir} ${if cfg.high-memory then "${bitcoind.dataDir}" else ""}";
|
ReadWritePaths = "${cfg.dataDir} ${if cfg.high-memory then "${bitcoind.dataDir}" else ""}";
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.${cfg.user} = {
|
users.users.${cfg.user} = {
|
||||||
|
|
|
@ -102,9 +102,7 @@ in {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
ReadWritePaths = cfg.dataDir;
|
ReadWritePaths = cfg.dataDir;
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
nix-bitcoin.secrets = {
|
nix-bitcoin.secrets = {
|
||||||
|
|
|
@ -100,9 +100,7 @@ in {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
ReadWritePaths = cfg.dataDir;
|
ReadWritePaths = cfg.dataDir;
|
||||||
} // (if cfg.enforceTor
|
} // (nbLib.allowedIPAddresses cfg.enforceTor);
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,10 +239,7 @@ in {
|
||||||
PIDFile = pidFile;
|
PIDFile = pidFile;
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
ReadWritePaths = cfg.dataDir;
|
ReadWritePaths = cfg.dataDir;
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.${cfg.user} = {
|
users.users.${cfg.user} = {
|
||||||
|
|
|
@ -262,10 +262,8 @@ in {
|
||||||
'') (attrNames cfg.macaroons)}
|
'') (attrNames cfg.macaroons)}
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor
|
||||||
then nbLib.allowTor
|
// nbLib.allowAnyProtocol; # For ZMQ
|
||||||
else nbLib.allowAnyIP
|
|
||||||
) // nbLib.allowAnyProtocol; # For ZMQ
|
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users.${cfg.user} = {
|
users.users.${cfg.user} = {
|
||||||
|
|
|
@ -83,9 +83,7 @@ in {
|
||||||
ExecStart = "${pkgs.bash}/bin/bash ${recurring-donations-script}";
|
ExecStart = "${pkgs.bash}/bin/bash ${recurring-donations-script}";
|
||||||
User = "recurring-donations";
|
User = "recurring-donations";
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP);
|
|
||||||
};
|
};
|
||||||
systemd.timers.recurring-donations = {
|
systemd.timers.recurring-donations = {
|
||||||
requires = [ "clightning.service" ];
|
requires = [ "clightning.service" ];
|
||||||
|
|
|
@ -79,9 +79,7 @@ in {
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "10s";
|
RestartSec = "10s";
|
||||||
} // (if cfg.enforceTor
|
} // nbLib.allowedIPAddresses cfg.enforceTor
|
||||||
then nbLib.allowTor
|
|
||||||
else nbLib.allowAnyIP)
|
|
||||||
// nbLib.nodejs;
|
// nbLib.nodejs;
|
||||||
};
|
};
|
||||||
nix-bitcoin.secrets.spark-wallet-login.user = cfg.user;
|
nix-bitcoin.secrets.spark-wallet-login.user = cfg.user;
|
||||||
|
|
14
pkgs/lib.nix
14
pkgs/lib.nix
|
@ -35,13 +35,17 @@ let self = {
|
||||||
|
|
||||||
# nodejs applications apparently rely on memory write execute
|
# nodejs applications apparently rely on memory write execute
|
||||||
nodejs = { MemoryDenyWriteExecute = "false"; };
|
nodejs = { MemoryDenyWriteExecute = "false"; };
|
||||||
# Allow tor traffic. Allow takes precedence over Deny.
|
|
||||||
allowTor = {
|
# Allow takes precedence over Deny.
|
||||||
|
allowLocalIPAddresses = {
|
||||||
IPAddressAllow = "127.0.0.1/32 ::1/128 169.254.0.0/16";
|
IPAddressAllow = "127.0.0.1/32 ::1/128 169.254.0.0/16";
|
||||||
};
|
};
|
||||||
# Allow any traffic
|
allowAllIPAddresses = { IPAddressAllow = "any"; };
|
||||||
allowAnyIP = { IPAddressAllow = "any"; };
|
allowTor = self.allowLocalIPAddresses;
|
||||||
allowAnyProtocol = { RestrictAddressFamilies = "~"; };
|
allowedIPAddresses = onlyLocal:
|
||||||
|
if onlyLocal
|
||||||
|
then self.allowLocalIPAddresses
|
||||||
|
else self.allowAllIPAddresses;
|
||||||
|
|
||||||
enforceTor = mkOption {
|
enforceTor = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user