Comprehensive Guide to Monitoring NixOS with NCPA in Nagios XI


NixOS is a distinctive Linux distribution known for its declarative configuration, atomic upgrades, and reproducible builds, leveraging the Nix package manager. Unlike traditional distributions, NixOS doesn’t natively support RPM-based packages like the Nagios Cross-Platform Agent (NCPA) from standard repositories. However, NCPA can be manually installed to monitor system metrics such as CPU usage, memory, disk usage, and processes, integrating seamlessly with Nagios XI for real-time oversight. This guide details the manual installation and configuration of NCPA (latest version as of March 2025) on NixOS and its integration with Nagios XI, tailored to NixOS’s unique environment.
Prerequisites
Ensure:
- A NixOS system (updated with
sudo nix-channel --update && sudo nixos-rebuild switch
) withsudo
or root access. - A running Nagios XI instance (latest version recommended).
- Network connectivity between NixOS and Nagios XI (port 5693/TCP open).
- Basic utilities installed:
curl
,rpm2cpio
,cpio
, andpython3
(not all are default in NixOS).
Step 1: Prepare the Environment
NixOS requires specific tools to extract the NCPA RPM, which aren’t included by default:
1. Install Required Tools:
sudo nix-env -iA nixos.curl nixos.rpm-tools nixos.cpio
2. Verify Installation:
curl --version rpm2cpio --version cpio --version
- Declarative Alternative:
environment.systemPackages = with pkgs; [ curl rpm-tools cpio ];
- Then run:
sudo nixos-rebuild switch
Step 2: Download and Extract NCP
1. Create a Working Directory:
mkdir -p ~/ncpa && cd ~/ncpa
2. Download the Latest NCPA RPM:
curl -O https://assets.nagios.com/downloads/ncpa3/ncpa-latest-1.x86_64.rpm
3. Extract the RPM:
rpm2cpio ncpa-latest-1.x86_64.rpm | cpio -idmv
Step 3: Install NCPA Files Manually
sudo cp -r ./usr/* /usr/
sudo cp -r ./etc/* /etc/
sudo cp -r ./var/* /var/
Step 4: Configure NCPA
1. Edit the Config File:
sudo nano /usr/local/ncpa/etc/ncpa.cfg
2. Update the token:
- Locate:
community_string = mytoken
- Replace with:
community_string = Str0ngT0k3n2025
- Save and exit (Ctrl+O, Enter, Ctrl+X in nano).
Step 5: Start NCPA
NixOS uses systemd but prefers declarative service management. Start NCPA manually or create a custom systemd unit:
Option 1: Manual Start
sudo /usr/local/ncpa/ncpa_listener &
- Runs in the background; use fg to bring it forward or kill to stop it.
Option 2: Create a Systemd Unit
1. Create a Service File:
sudo nano /etc/systemd/system/ncpa.service
Add the Following:
[Unit]
Description=NCPA Listener Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/ncpa/ncpa_listener
Restart=on-failure
[Install]
WantedBy=multi-user.target
Enable and Start:
sudo systemctl daemon-reload
sudo systemctl enable ncpa
sudo systemctl start ncpa
Declarative Alternative: Add to /etc/nixos/configuration.nix:
systemd.services.ncpa = {
description = "NCPA Listener Service";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "/usr/local/ncpa/ncpa_listener";
Restart = "on-failure";
};
};
Then run:
sudo nixos-rebuild switch
Step 6: Configure Firewall
sudo iptables -I INPUT -p tcp --dport 5693 -j ACCEPT
sudo mkdir -p /etc/iptables
sudo iptables-save > /etc/iptables/rules.v4
verify:
sudo iptables -L -n | grep 5693
Declarative Firewall: Add to /etc/nixos/configuration.nix:
networking.firewall.allowedTCPPorts = [ 5693 ];
Then run:
sudo nixos-rebuild switch
Step 7: Test NCPA Access
1. Access the NCPA Web Interface:
- Open a browser:
https://<NixOS-IP>:5693/
2. Accept Certificate:
- Accept the self-signed certificate warning.
3. Log In:
- Verify metrics like CPU, memory, and disk usage are displayed.
- Use the token (e.g., Str0ngT0k3n2025) to access the dashboard.
Step 8: Add NixOS to Nagios XI
1. Log into Nagios XI:
- Access the web interface.
2. Run the NCPA Wizard:
- Navigate to Configure > Configuration Wizards.
- Select NCPA.

3. Configure the Host:
- IP Address: Enter the NixOS IP (e.g., 192.168.0.31).
- Port: Use 5693.
- Token: Input Str0ngT0k3n2025.
- Metrics: Select CPU Usage, Memory Usage, Disk Usage, Processes, etc.
- Set thresholds (e.g., CPU warning at 80%, critical at 90%).

4. Apply Configuration:
- Click Finish and apply changes.
5. Verify Monitoring:
- Go to Monitoring > Hosts, locate your NixOS host, and check service statuses.
Troubleshooting
#Check process:
ps aux | grep ncpa_listener
#Check systemd (if used):
sudo systemctl status ncpa
#Review logs:
cat /usr/local/ncpa/var/log/ncpa.log
#Test connectivity:
nc -zv <NixOS-IP> 5693
#Check firewall:
iptables -L -n
cat /usr/local/nagiosxi/var/ncpa.log
Conclusion
You’ve manually installed NCPA on NixOS and integrated it with Nagios XI as of March 28, 2025. While NixOS’s declarative nature doesn’t align with NCPA’s standard RPM packaging, this workaround enables robust monitoring. For a more Nix-native approach, consider packaging NCPA as a Nix derivation or persisting files in /opt
and managing services/firewall declaratively in /etc/nixos/configuration.nix
. Explore further customization like passive checks via NRDP in the Nagios NCPA , Nagios Knowledgebase, or NixOS Documentation.