summary refs log tree commit diff
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2021-04-23 12:15:27 +0200
committerpennae <github@quasiparticle.net>2021-04-23 16:16:37 +0200
commit265d31bcbd6599c38499354bc5f111589814f101 (patch)
tree886239dd44085b1218c3de6527298ecfa634c01f
parent842f900e73c7ce985218cc4f455e34d1d56475c1 (diff)
downloadnixpkgs-265d31bcbd6599c38499354bc5f111589814f101.tar
nixpkgs-265d31bcbd6599c38499354bc5f111589814f101.tar.gz
nixpkgs-265d31bcbd6599c38499354bc5f111589814f101.tar.bz2
nixpkgs-265d31bcbd6599c38499354bc5f111589814f101.tar.lz
nixpkgs-265d31bcbd6599c38499354bc5f111589814f101.tar.xz
nixpkgs-265d31bcbd6599c38499354bc5f111589814f101.tar.zst
nixpkgs-265d31bcbd6599c38499354bc5f111589814f101.zip
nixos/sshguard: restart sshguard when services/backend changes
backends changing shouldn't be very likely, but services may well change. we
should restart sshguard from nixos-rebuild instead of merely plopping down a new
config file and waiting for the user to restart sshguard.
-rw-r--r--nixos/modules/services/security/sshguard.nix32
1 files changed, 18 insertions, 14 deletions
diff --git a/nixos/modules/services/security/sshguard.nix b/nixos/modules/services/security/sshguard.nix
index 033ff5ef4b5..53bd9efa5ac 100644
--- a/nixos/modules/services/security/sshguard.nix
+++ b/nixos/modules/services/security/sshguard.nix
@@ -5,6 +5,21 @@ with lib;
 let
   cfg = config.services.sshguard;
 
+  configFile = let
+    args = lib.concatStringsSep " " ([
+      "-afb"
+      "-p info"
+      "-o cat"
+      "-n1"
+    ] ++ (map (name: "-t ${escapeShellArg name}") cfg.services));
+    backend = if config.networking.nftables.enable
+      then "sshg-fw-nft-sets"
+      else "sshg-fw-ipset";
+  in pkgs.writeText "sshguard.conf" ''
+    BACKEND="${pkgs.sshguard}/libexec/${backend}"
+    LOGREADER="LANG=C ${pkgs.systemd}/bin/journalctl ${args}"
+  '';
+
 in {
 
   ###### interface
@@ -85,20 +100,7 @@ in {
 
   config = mkIf cfg.enable {
 
-    environment.etc."sshguard.conf".text = let
-      args = lib.concatStringsSep " " ([
-        "-afb"
-        "-p info"
-        "-o cat"
-        "-n1"
-      ] ++ (map (name: "-t ${escapeShellArg name}") cfg.services));
-      backend = if config.networking.nftables.enable
-        then "sshg-fw-nft-sets"
-        else "sshg-fw-ipset";
-    in ''
-      BACKEND="${pkgs.sshguard}/libexec/${backend}"
-      LOGREADER="LANG=C ${pkgs.systemd}/bin/journalctl ${args}"
-    '';
+    environment.etc."sshguard.conf".source = configFile;
 
     systemd.services.sshguard = {
       description = "SSHGuard brute-force attacks protection system";
@@ -107,6 +109,8 @@ in {
       after = [ "network.target" ];
       partOf = optional config.networking.firewall.enable "firewall.service";
 
+      restartTriggers = [ configFile ];
+
       path = with pkgs; if config.networking.nftables.enable
         then [ nftables iproute2 systemd ]
         else [ iptables ipset iproute2 systemd ];