final
This commit is contained in:
parent
a8115e76f8
commit
6079633b13
5 changed files with 61 additions and 45 deletions
10
common.nix
10
common.nix
|
|
@ -34,15 +34,7 @@
|
||||||
];
|
];
|
||||||
i18n.defaultLocale = "ru_RU.UTF-8";
|
i18n.defaultLocale = "ru_RU.UTF-8";
|
||||||
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
|
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
|
||||||
networking.networkmanager = {
|
networking.networkmanager.enable = true;
|
||||||
enable = true;
|
|
||||||
insertNameservers = [
|
|
||||||
"1.0.0.2"
|
|
||||||
"1.1.1.2"
|
|
||||||
"2606:4700:4700::1002"
|
|
||||||
"2606:4700:4700::1112"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
nix.settings.experimental-features = [
|
nix.settings.experimental-features = [
|
||||||
"flakes"
|
"flakes"
|
||||||
"nix-command"
|
"nix-command"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
{ config, pkgs, ... }: {
|
{ config, pkgs, ... }: {
|
||||||
networking = {
|
networking = {
|
||||||
firewall = {
|
firewall = {
|
||||||
allowedTCPPorts = [
|
allowedTCPPorts = [ 2049 ];
|
||||||
2049
|
|
||||||
53
|
|
||||||
];
|
|
||||||
allowedUDPPorts = [
|
allowedUDPPorts = [
|
||||||
53
|
|
||||||
547
|
547
|
||||||
69
|
69
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,13 @@
|
||||||
./vps-init.nix
|
./vps-init.nix
|
||||||
];
|
];
|
||||||
networking = {
|
networking = {
|
||||||
firewall.allowedUDPPorts = [ 67 ];
|
firewall = {
|
||||||
|
allowedTCPPorts = [ 53 ];
|
||||||
|
allowedUDPPorts = [
|
||||||
|
53
|
||||||
|
67
|
||||||
|
];
|
||||||
|
};
|
||||||
nat.enable = true;
|
nat.enable = true;
|
||||||
networkmanager.ensureProfiles = {
|
networkmanager.ensureProfiles = {
|
||||||
environmentFiles = [ config.sops.secrets.wifi-env.path ];
|
environmentFiles = [ config.sops.secrets.wifi-env.path ];
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
{ config, pkgs, ... }: {
|
{ config, pkgs, ... }: {
|
||||||
boot.kernelParams = [ "cfg80211.ieee80211_regdom=RU" "consoleblank=60" ];
|
boot.kernelParams = [
|
||||||
|
"cfg80211.ieee80211_regdom=RU"
|
||||||
|
"consoleblank=60"
|
||||||
|
];
|
||||||
imports = [
|
imports = [
|
||||||
../mods/host.nix
|
../mods/host.nix
|
||||||
./hardware.nix
|
./hardware.nix
|
||||||
|
|
@ -19,15 +22,10 @@
|
||||||
allowedUDPPorts = [ 443 ];
|
allowedUDPPorts = [ 443 ];
|
||||||
};
|
};
|
||||||
hostName = "nixos-server";
|
hostName = "nixos-server";
|
||||||
nat = {
|
nat.internalInterfaces = [ "wlp2s0" ];
|
||||||
extraCommands = ''
|
networkmanager = {
|
||||||
${pkgs.iproute2}/bin/ip rule add lookup main priority 29588 from \
|
ensureProfiles.profiles = {
|
||||||
${config.networking.networkmanager.ensureProfiles.profiles.home-wifi.ipv4.addresses}
|
dhcp-ethernet.ethernet.cloned-mac-address = "0C:0E:76:A6:E6:B6";
|
||||||
'';
|
|
||||||
internalInterfaces = [ "wlp2s0" ];
|
|
||||||
};
|
|
||||||
networkmanager.ensureProfiles.profiles = {
|
|
||||||
#dhcp-ethernet.ethernet.cloned-mac-address = "0C:0E:76:A6:E6:B6";
|
|
||||||
home-wifi = {
|
home-wifi = {
|
||||||
ipv4 = {
|
ipv4 = {
|
||||||
addresses = "10.1.0.1/16";
|
addresses = "10.1.0.1/16";
|
||||||
|
|
@ -46,6 +44,13 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
insertNameservers = [
|
||||||
|
"1.0.0.2"
|
||||||
|
"1.1.1.2"
|
||||||
|
"2606:4700:4700::1002"
|
||||||
|
"2606:4700:4700::1112"
|
||||||
|
];
|
||||||
|
};
|
||||||
wg-quick.interfaces.awg0.configFile = config.sops.templates.awg1-conf.path;
|
wg-quick.interfaces.awg0.configFile = config.sops.templates.awg1-conf.path;
|
||||||
};
|
};
|
||||||
security.acme = {
|
security.acme = {
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,28 @@
|
||||||
sops.secrets.tgbot-env = { };
|
sops.secrets.tgbot-env = { };
|
||||||
systemd = {
|
systemd = {
|
||||||
services = {
|
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 = {
|
network-watchdog = {
|
||||||
|
path = with pkgs; [
|
||||||
|
curl
|
||||||
|
iputils
|
||||||
|
util-linux
|
||||||
|
];
|
||||||
script = ''
|
script = ''
|
||||||
exec {lock_fd}> /run/network.lock
|
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 ] || \
|
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
|
limit=3
|
||||||
failures=0
|
failures=0
|
||||||
else
|
else
|
||||||
|
|
@ -33,7 +49,7 @@
|
||||||
if [ $failures -ge $limit ]; then
|
if [ $failures -ge $limit ]; then
|
||||||
echo "<4>Restarting network"
|
echo "<4>Restarting network"
|
||||||
systemctl restart NetworkManager.service
|
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
|
systemctl restart wg-quick-awg0.service
|
||||||
[ $limit -lt 360 ] && limit=$((2*$limit))
|
[ $limit -lt 360 ] && limit=$((2*$limit))
|
||||||
failures=0
|
failures=0
|
||||||
|
|
@ -47,13 +63,14 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
tgbot-send = {
|
tgbot-send = {
|
||||||
|
path = [ pkgs.curl ];
|
||||||
script = ''
|
script = ''
|
||||||
. ${config.sops.secrets.tgbot-env.path}
|
. ${config.sops.secrets.tgbot-env.path}
|
||||||
for msg in "''${MESSAGES[@]}"; do
|
for msg in "''${MESSAGES[@]}"; do
|
||||||
CHAT_ID="''${msg%%:*}"
|
CHAT_ID="''${msg%%:*}"
|
||||||
TEXT="''${msg#*:}"
|
TEXT="''${msg#*:}"
|
||||||
${pkgs.curl}/bin/curl -X POST "https://api.telegram.org/$BOT/sendMessage" \
|
curl -X POST "https://api.telegram.org/$BOT/sendMessage" \
|
||||||
-d "chat_id=$CHAT_ID" -d "text=$TEXT" 2> /dev/null | ${pkgs.jq}/bin/jq
|
-d "chat_id=$CHAT_ID" -d "text=$TEXT" | ${pkgs.jq}/bin/jq
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue