final setup for router, tested
This commit is contained in:
parent
c31dc86310
commit
58ce5e8a6c
6 changed files with 53 additions and 25 deletions
|
|
@ -1,5 +1,8 @@
|
|||
{ config, pkgs, ... }: {
|
||||
boot.kernelParams = [ "consoleblank=60" ];
|
||||
boot.kernelParams = [
|
||||
"cfg80211.ieee80211_regdom=RU"
|
||||
"consoleblank=60"
|
||||
];
|
||||
imports = [
|
||||
../mods/host.nix
|
||||
./hardware.nix
|
||||
|
|
@ -19,23 +22,25 @@
|
|||
allowedUDPPorts = [ 443 ];
|
||||
};
|
||||
hostName = "nixos-server";
|
||||
nat.internalInterfaces = [ "wlp2s0" ];
|
||||
networkmanager.ensureProfiles.profiles = {
|
||||
dhcp-ethernet.connection.cloned-mac-address = "0C:0E:76:A6:E6:B6";
|
||||
dhcp-ethernet.ethernet.cloned-mac-address = "0C:0E:76:A6:E6:B6";
|
||||
home-wifi = {
|
||||
ipv4 = {
|
||||
addresses = "10.1.0.1/16";
|
||||
method = "shared";
|
||||
};
|
||||
ipv6 = {
|
||||
addresses = "fc01::1/64";
|
||||
method = "shared";
|
||||
};
|
||||
wifi = {
|
||||
band = "a";
|
||||
channel = 157;
|
||||
channel-width = 80;
|
||||
mode = "ap";
|
||||
};
|
||||
wifi-security = {
|
||||
group = "ccmp";
|
||||
pairwise = "ccmp";
|
||||
proto = "rsn";
|
||||
};
|
||||
};
|
||||
};
|
||||
wg-quick.interfaces.awg0.configFile = config.sops.templates.awg1-conf.path;
|
||||
|
|
|
|||
|
|
@ -18,12 +18,28 @@
|
|||
sops.secrets.tgbot-env = { };
|
||||
systemd = {
|
||||
services = {
|
||||
hotspot-routing = {
|
||||
after = [ "wg-quick-awg0.service" ];
|
||||
path = [ pkgs.iproute2 ];
|
||||
preStop = "ip rule del from 10.1.0.0/16 lookup main";
|
||||
requiredBy = [ "wg-quick-awg0.service" ];
|
||||
script = "ip rule add from 10.1.0.0/16 lookup main";
|
||||
serviceConfig = {
|
||||
RemainAfterExit = true;
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
network-watchdog = {
|
||||
path = with pkgs; [
|
||||
curl
|
||||
iputils
|
||||
util-linux
|
||||
];
|
||||
script = ''
|
||||
exec {lock_fd}> /run/network.lock
|
||||
${pkgs.util-linux}/bin/flock -n $lock_fd || exit
|
||||
flock -n $lock_fd || exit
|
||||
if [ ! -e /run/network.failures ] || [ ! -e /run/network.limit ] || \
|
||||
${pkgs.curl}/bin/curl --head --max-time 3 https://bogaledev.ru; then
|
||||
curl --head --max-time 3 https://bogaledev.ru; then
|
||||
limit=3
|
||||
failures=0
|
||||
else
|
||||
|
|
@ -33,7 +49,7 @@
|
|||
if [ $failures -ge $limit ]; then
|
||||
echo "<4>Restarting network"
|
||||
systemctl restart NetworkManager.service
|
||||
until ${pkgs.iputils}/bin/ping 10.1.0.1 -c 1 -W 1; do sleep 1; done
|
||||
until ping 10.1.0.1 -c 1 -W 1; do sleep 1; done
|
||||
systemctl restart wg-quick-awg0.service
|
||||
[ $limit -lt 360 ] && limit=$((2*$limit))
|
||||
failures=0
|
||||
|
|
@ -41,16 +57,20 @@
|
|||
echo $limit > /run/network.limit
|
||||
echo $failures > /run/network.failures
|
||||
'';
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig = {
|
||||
LogLevelMax = "warning";
|
||||
Type = "oneshot";
|
||||
};
|
||||
};
|
||||
tgbot-send = {
|
||||
path = [ pkgs.curl ];
|
||||
script = ''
|
||||
. ${config.sops.secrets.tgbot-env.path}
|
||||
for msg in "''${MESSAGES[@]}"; do
|
||||
CHAT_ID="''${msg%%:*}"
|
||||
TEXT="''${msg#*:}"
|
||||
${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/$BOT/sendMessage" \
|
||||
-d "chat_id=$CHAT_ID" -d "text=$TEXT" 2> /dev/null | ${pkgs.jq}/bin/jq
|
||||
curl -X POST "https://api.telegram.org/$BOT/sendMessage" \
|
||||
-d "chat_id=$CHAT_ID" -d "text=$TEXT" | ${pkgs.jq}/bin/jq
|
||||
sleep 1
|
||||
done
|
||||
'';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue