<commit_before>{config, pkgs}:

let

  nagiosUser = "nagios";
  nagiosGroup = "nogroup";

  nagiosState = "/var/lib/nagios";
  nagiosLogDir = "/var/log/nagios";

  nagiosObjectDefs = [
    ./timeperiods.cfg
    ./host-templates.cfg
    ./service-templates.cfg
    ./commands.cfg
  ] ++ config.services.nagios.objectDefs;

  nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {}
    "ensureDir $out; ln -s ${toString nagiosObjectDefs} $out/";

  nagiosCfgFile = pkgs.writeText "nagios.cfg" "
  
    # Paths for state and logs.
    log_file=${nagiosLogDir}/current
    log_archive_path=${nagiosLogDir}/archive
    status_file=${nagiosState}/status.dat
    object_cache_file=${nagiosState}/objects.cache
    comment_file=${nagiosState}/comment.dat
    downtime_file=${nagiosState}/downtime.dat
    temp_file=${nagiosState}/nagios.tmp
    lock_file=/var/run/nagios.lock # Not used I think.
    state_retention_file=${nagiosState}/retention.dat

    # Configuration files.
    #resource_file=resource.cfg
    cfg_dir=${nagiosObjectDefsDir}

    # Uid/gid that the daemon runs under.
    nagios_user=${nagiosUser}
    nagios_group=${nagiosGroup}

    # Misc. options.
    illegal_macro_output_chars=`~$&|'\"<>
    retain_state_information=1
    
  ";

in

{
  name = "nagios";
  
  users = [
    { name = nagiosUser;
      uid = (import ../../system/ids.nix).uids.nagios;
      description = "Nagios monitoring daemon";
      home = nagiosState;
    }
  ];

  # Run `nagios -v' to check the validity of the configuration file so
  # that a nixos-rebuild fails *before* we kill the running Nagios
  # daemon.
  buildHook = "${pkgs.nagios}/bin/nagios -v ${nagiosCfgFile}";

  job = "
    description \"Nagios monitoring daemon\"

    start on network-interfaces/started
    stop on network-interfaces/stop

    start script
      mkdir -m 0755 -p ${nagiosState} ${nagiosLogDir}
      chown ${nagiosUser} ${nagiosState} ${nagiosLogDir}
    end script

    respawn

    script
      for i in ${toString config.services.nagios.plugins}; do
        export PATH=$i/bin:$i/sbin:$i/libexec:$PATH
      done
      exec ${pkgs.nagios}/bin/nagios ${nagiosCfgFile}
    end script
  ";
  
}
<commit_msg>* Make the Nagios configuration visible in /etc/nagios.cfg.<commit_after>{config, pkgs}:

let

  nagiosUser = "nagios";
  nagiosGroup = "nogroup";

  nagiosState = "/var/lib/nagios";
  nagiosLogDir = "/var/log/nagios";

  nagiosObjectDefs = [
    ./timeperiods.cfg
    ./host-templates.cfg
    ./service-templates.cfg
    ./commands.cfg
  ] ++ config.services.nagios.objectDefs;

  nagiosObjectDefsDir = pkgs.runCommand "nagios-objects" {}
    "ensureDir $out; ln -s ${toString nagiosObjectDefs} $out/";

  nagiosCfgFile = pkgs.writeText "nagios.cfg" "
  
    # Paths for state and logs.
    log_file=${nagiosLogDir}/current
    log_archive_path=${nagiosLogDir}/archive
    status_file=${nagiosState}/status.dat
    object_cache_file=${nagiosState}/objects.cache
    comment_file=${nagiosState}/comment.dat
    downtime_file=${nagiosState}/downtime.dat
    temp_file=${nagiosState}/nagios.tmp
    lock_file=/var/run/nagios.lock # Not used I think.
    state_retention_file=${nagiosState}/retention.dat

    # Configuration files.
    #resource_file=resource.cfg
    cfg_dir=${nagiosObjectDefsDir}

    # Uid/gid that the daemon runs under.
    nagios_user=${nagiosUser}
    nagios_group=${nagiosGroup}

    # Misc. options.
    illegal_macro_output_chars=`~$&|'\"<>
    retain_state_information=1
    
  ";

in

{
  name = "nagios";
  
  users = [
    { name = nagiosUser;
      uid = (import ../../system/ids.nix).uids.nagios;
      description = "Nagios monitoring daemon";
      home = nagiosState;
    }
  ];

  extraPath = [pkgs.nagios];

  # This isn't needed, it's just so that the user can type "nagiostats
  # -c /etc/nagios.cfg".
  extraEtc = [
    { source = nagiosCfgFile;
      target = "nagios.cfg";
    }
  ];

  # Run `nagios -v' to check the validity of the configuration file so
  # that a nixos-rebuild fails *before* we kill the running Nagios
  # daemon.
  buildHook = "${pkgs.nagios}/bin/nagios -v ${nagiosCfgFile}";

  job = "
    description \"Nagios monitoring daemon\"

    start on network-interfaces/started
    stop on network-interfaces/stop

    start script
      mkdir -m 0755 -p ${nagiosState} ${nagiosLogDir}
      chown ${nagiosUser} ${nagiosState} ${nagiosLogDir}
    end script

    respawn

    script
      for i in ${toString config.services.nagios.plugins}; do
        export PATH=$i/bin:$i/sbin:$i/libexec:$PATH
      done
      exec ${pkgs.nagios}/bin/nagios ${nagiosCfgFile}
    end script
  ";
  
}

{'fraction_non_alphanumeric': 0.12931778929188256, 'fraction_numerical': 0.002158894645941278, 'mean_word_length': 3.0569176882661995, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2467834', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1677, 'n_words': 322}