start/stop firewall commands

This commit is contained in:
Motiejus Jakštys 2023-07-26 15:10:39 +03:00
parent ab11ee31f2
commit 4522af453b
3 changed files with 87 additions and 79 deletions

View File

@ -15,10 +15,12 @@
services.sshguard = { services.sshguard = {
enable = true; enable = true;
blocktime = 900; blocktime = 900;
whitelist = [ whitelist =
"192.168.0.0/16" [
myData.tailscale_subnet.cidr "192.168.0.0/16"
] ++ (lib.catAttrs "publicIP" (lib.attrValues myData.hosts)); myData.tailscale_subnet.cidr
]
++ (lib.catAttrs "publicIP" (lib.attrValues myData.hosts));
}; };
}; };
} }

View File

@ -19,7 +19,10 @@ in {
enable = lib.mkEnableOption "backup zfs snapshots with borg"; enable = lib.mkEnableOption "backup zfs snapshots with borg";
passwordPath = lib.mkOption {type = str;}; passwordPath = lib.mkOption {type = str;};
sshKeyPath = lib.mkOption {type = nullOr path; default = null;}; sshKeyPath = lib.mkOption {
type = nullOr path;
default = null;
};
mountpoints = lib.mkOption { mountpoints = lib.mkOption {
default = {}; default = {};
@ -87,7 +90,8 @@ in {
} }
// lib.optionalAttrs (attrs ? patterns) { // lib.optionalAttrs (attrs ? patterns) {
patterns = attrs.patterns; patterns = attrs.patterns;
} // lib.optionalAttrs (config.mj.base.zfsborg.sshKeyPath != null) { }
// lib.optionalAttrs (config.mj.base.zfsborg.sshKeyPath != null) {
environment.BORG_RSH = ''ssh -i "${config.mj.base.zfsborg.sshKeyPath}"''; environment.BORG_RSH = ''ssh -i "${config.mj.base.zfsborg.sshKeyPath}"'';
}; };
}) })

View File

@ -13,84 +13,86 @@ in {
dataDir = lib.mkOption {type = path;}; dataDir = lib.mkOption {type = path;};
}; };
config = lib.mkIf config.mj.services.syncthing.enable { config = let
networking.firewall.extraCommands = let hosts = lib.attrVals ["mxp10.motiejus.jakst" "fwmine.motiejus.jakst"] myData.hosts;
hosts = lib.attrVals ["mxp10.motiejus.jakst" "fwmine.motiejus.jakst"] myData.hosts; ips = lib.catAttrs "jakstIP" hosts;
ips = lib.catAttrs "jakstIP" hosts; startLines = map (ip: "iptables -A INPUT -p tcp --dport 8384 -s ${ip} -j ACCEPT") ips;
lines = map (ip: "iptables -A INPUT -p tcp --dport 8384 -s ${ip} -j ACCEPT") ips; stopLines = map (ip: "iptables -D INPUT -p tcp --dport 8384 -s ${ip} -j ACCEPT") ips;
in in
lib.concatLines lines; lib.mkIf config.mj.services.syncthing.enable {
networking.firewall.extraCommands = lib.concatLines startLines;
networking.firewall.extraStopCommands = lib.concatLines stopLines;
services.syncthing = { services.syncthing = {
enable = config.mj.services.syncthing.enable; enable = config.mj.services.syncthing.enable;
openDefaultPorts = true; openDefaultPorts = true;
guiAddress = let guiAddress = let
fqdn = with config.networking; "${hostName}.${domain}"; fqdn = with config.networking; "${hostName}.${domain}";
jakstIP = lib.getAttrFromPath [fqdn "jakstIP"] myData.hosts; jakstIP = lib.getAttrFromPath [fqdn "jakstIP"] myData.hosts;
guiPortStr = builtins.toString guiPort; guiPortStr = builtins.toString guiPort;
in "${jakstIP}:${guiPortStr}"; in "${jakstIP}:${guiPortStr}";
user = config.mj.services.syncthing.user; user = config.mj.services.syncthing.user;
group = config.mj.services.syncthing.group; group = config.mj.services.syncthing.group;
dataDir = config.mj.services.syncthing.dataDir; dataDir = config.mj.services.syncthing.dataDir;
extraOptions.gui.insecureAdminAccess = true; extraOptions.gui.insecureAdminAccess = true;
devices = devices =
{} {}
// (lib.optionalAttrs (config.networking.hostName == "vno1-oh2") { // (lib.optionalAttrs (config.networking.hostName == "vno1-oh2") {
"fwmine".id = "GKSUKZE-AOBQOWY-CNLZ2ZI-WNKATYE-MV4Y452-J3VCJ5C-EAANXRX-2P6EHA6"; "fwmine".id = "GKSUKZE-AOBQOWY-CNLZ2ZI-WNKATYE-MV4Y452-J3VCJ5C-EAANXRX-2P6EHA6";
"mxp10".id = "LO54QZZ-5J3G62P-WUVM3MW-7J3VWHD-BG76TOQ-5S7PZSY-JU45K3I-X3ZL4AN"; "mxp10".id = "LO54QZZ-5J3G62P-WUVM3MW-7J3VWHD-BG76TOQ-5S7PZSY-JU45K3I-X3ZL4AN";
"rzj-744P2PE".id = "UW6ISH2-NW6X6AW-BJR76TV-TV3BIGZ-PA5QH2M-YEF567T-IWMHKD5-P3XHHAH"; "rzj-744P2PE".id = "UW6ISH2-NW6X6AW-BJR76TV-TV3BIGZ-PA5QH2M-YEF567T-IWMHKD5-P3XHHAH";
}) })
// {}; // {};
folders = { folders = {
"${config.services.syncthing.dataDir}/annex2/Books" = { "${config.services.syncthing.dataDir}/annex2/Books" = {
devices = ["mxp10" "fwmine"]; devices = ["mxp10" "fwmine"];
id = "8lk0n-mm63y"; id = "8lk0n-mm63y";
label = "Books"; label = "Books";
}; };
"${config.services.syncthing.dataDir}/annex2/M-Active" = { "${config.services.syncthing.dataDir}/annex2/M-Active" = {
devices = ["mxp10" "fwmine"]; devices = ["mxp10" "fwmine"];
id = "f6fma-unkxq"; id = "f6fma-unkxq";
label = "M-Active"; label = "M-Active";
}; };
"${config.services.syncthing.dataDir}/annex2/M-Camera" = { "${config.services.syncthing.dataDir}/annex2/M-Camera" = {
devices = ["mxp10" "fwmine"]; devices = ["mxp10" "fwmine"];
id = "pixel_xl_dtm3-photos"; id = "pixel_xl_dtm3-photos";
label = "M-Active"; label = "M-Active";
}; };
"${config.services.syncthing.dataDir}/annex2/M-Documents" = { "${config.services.syncthing.dataDir}/annex2/M-Documents" = {
devices = ["fwmine"]; devices = ["fwmine"];
id = "4fu7z-z6es2"; id = "4fu7z-z6es2";
label = "M-Documents"; label = "M-Documents";
}; };
"${config.services.syncthing.dataDir}/annex2/R-Documents" = { "${config.services.syncthing.dataDir}/annex2/R-Documents" = {
devices = ["rzj-744P2PE"]; devices = ["rzj-744P2PE"];
id = "nm23h-aog6k"; id = "nm23h-aog6k";
label = "R-Documents"; label = "R-Documents";
}; };
"${config.services.syncthing.dataDir}/annex2/Pictures" = { "${config.services.syncthing.dataDir}/annex2/Pictures" = {
devices = ["fwmine"]; devices = ["fwmine"];
id = "d3hur-cbzyw"; id = "d3hur-cbzyw";
label = "Pictures"; label = "Pictures";
}; };
"${config.services.syncthing.dataDir}/stud-cache" = { "${config.services.syncthing.dataDir}/stud-cache" = {
devices = ["fwmine"]; devices = ["fwmine"];
id = "2kq7n-jqzxj"; id = "2kq7n-jqzxj";
label = "stud-cache"; label = "stud-cache";
}; };
"${config.services.syncthing.dataDir}/video/shared" = { "${config.services.syncthing.dataDir}/video/shared" = {
devices = ["mxp10" "fwmine"]; devices = ["mxp10" "fwmine"];
id = "byzmw-f6zhg"; id = "byzmw-f6zhg";
label = "video-shared"; label = "video-shared";
}; };
"${config.services.syncthing.dataDir}/music" = { "${config.services.syncthing.dataDir}/music" = {
devices = ["fwmine" "mxp10"]; devices = ["fwmine" "mxp10"];
id = "tg94v-cqcwr"; id = "tg94v-cqcwr";
label = "music"; label = "music";
};
}; };
}; };
}; };
};
} }