summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authoraanderse <aaron@fosslib.net>2018-10-27 13:01:30 -0400
committerRenaud <c0bw3b@users.noreply.github.com>2018-10-27 19:01:30 +0200
commit1381019e49b8403aaf10c9b3ecb80e138d7e304d (patch)
treecf225ccd96dcde8e689a89e5ce58328ef29d7427 /nixos
parentd6a15b09c788a1acf4b39ef6aecdb8b2757e3f1b (diff)
downloadnixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.tar
nixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.tar.gz
nixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.tar.bz2
nixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.tar.lz
nixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.tar.xz
nixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.tar.zst
nixlib-1381019e49b8403aaf10c9b3ecb80e138d7e304d.zip
nixos/rsyslogd & nixos/syslog-ng: fix broken module (#47306)
* journald: forward message to syslog by default if a syslog implementation is installed

* added a test to ensure rsyslog is receiving messages when expected

* added rsyslogd tests to release.nix
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/system/boot/systemd.nix12
-rw-r--r--nixos/release.nix1
-rw-r--r--nixos/tests/rsyslogd.nix37
3 files changed, 50 insertions, 0 deletions
diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix
index a1412bc32904..3d9fa53ce522 100644
--- a/nixos/modules/system/boot/systemd.nix
+++ b/nixos/modules/system/boot/systemd.nix
@@ -587,6 +587,15 @@ in
       '';
     };
 
+    services.journald.forwardToSyslog = mkOption {
+      default = config.services.rsyslogd.enable || config.services.syslog-ng.enable;
+      defaultText = "config.services.rsyslogd.enable || config.services.syslog-ng.enable";
+      type = types.bool;
+      description = ''
+        Whether to forward log messages to syslog.
+      '';
+    };
+
     services.logind.extraConfig = mkOption {
       default = "";
       type = types.lines;
@@ -754,6 +763,9 @@ in
           ForwardToConsole=yes
           TTYPath=${config.services.journald.console}
         ''}
+        ${optionalString (config.services.journald.forwardToSyslog) ''
+          ForwardToSyslog=yes
+        ''}
         ${config.services.journald.extraConfig}
       '';
 
diff --git a/nixos/release.nix b/nixos/release.nix
index 5412080cca18..46dbe4aa77b2 100644
--- a/nixos/release.nix
+++ b/nixos/release.nix
@@ -399,6 +399,7 @@ in rec {
   tests.radicale = callTest tests/radicale.nix {};
   tests.redmine = callTest tests/redmine.nix {};
   tests.rspamd = callSubTests tests/rspamd.nix {};
+  tests.rsyslogd = callSubTests tests/rsyslogd.nix {};
   tests.runInMachine = callTest tests/run-in-machine.nix {};
   tests.rxe = callTest tests/rxe.nix {};
   tests.samba = callTest tests/samba.nix {};
diff --git a/nixos/tests/rsyslogd.nix b/nixos/tests/rsyslogd.nix
new file mode 100644
index 000000000000..4836419f0c2f
--- /dev/null
+++ b/nixos/tests/rsyslogd.nix
@@ -0,0 +1,37 @@
+{ system ? builtins.currentSystem }:
+
+with import ../lib/testing.nix { inherit system; };
+{
+  test1 = makeTest {
+    name = "rsyslogd-test1";
+    meta.maintainers = [ lib.maintainers.aanderse ];
+
+    machine =
+      { config, pkgs, ... }:
+      { services.rsyslogd.enable = true;
+        services.journald.forwardToSyslog = false;
+      };
+
+    # ensure rsyslogd isn't receiving messages from journald if explicitly disabled
+    testScript = ''
+      $machine->waitForUnit("default.target");
+      $machine->fail("test -f /var/log/messages");
+    '';
+  };
+
+  test2 = makeTest {
+    name = "rsyslogd-test2";
+    meta.maintainers = [ lib.maintainers.aanderse ];
+
+    machine =
+      { config, pkgs, ... }:
+      { services.rsyslogd.enable = true;
+      };
+
+    # ensure rsyslogd is receiving messages from journald
+    testScript = ''
+      $machine->waitForUnit("default.target");
+      $machine->succeed("test -f /var/log/messages");
+    '';
+  };
+}