{
  config,
  lib,
  pkgs,
  ...
}:
{
  options.services.netconsoleReceiver = {
    enable = lib.mkEnableOption "netconsole UDP receiver";
    port = lib.mkOption {
      type = lib.types.port;
      default = 6666;
      description = "UDP port to listen on for netconsole messages";
    };
  };

  config = lib.mkIf config.services.netconsoleReceiver.enable {
    systemd.services.netconsole-receiver = {
      description = "Netconsole UDP receiver";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      serviceConfig = {
        ExecStart = "${pkgs.socat}/bin/socat -u UDP-LISTEN:${toString config.services.netconsoleReceiver.port},fork STDOUT";
        StandardOutput = "journal";
        StandardError = "journal";
        SyslogIdentifier = "netconsole";
        Restart = "always";
        RestartSec = "5s";
      };
    };
  };
}
