1# The declarations in this file build the Datadog agent's core
2# integrations. These integrations are tracked in a separate
3# repository[1] outside of the agent's primary repository and provide
4# checks for various kinds of services.
5#
6# Not all services are relevant for all users, however. As some of
7# them depend on various tools and Python packages it is nonsensical
8# to build *all* integrations by default.
9#
10# A set of default integrations is defined and built either way.
11# Additional integrations can be specified by overriding
12# `extraIntegrations` in datadog-integrations-core.
13#
14# In practice the syntax for using this with additional integrations
15# is not the most beautiful, but it works. For example to use
16# datadog-agent from the top-level with the `ntp`-integration
17# included, one could say:
18#
19# let
20# integrationsWithNtp = datadog-integrations-core {
21# # Extra integrations map from the integration name (as in the
22# # integrations-core repository) to a function that receives the
23# # Python package set and returns the required dependencies.g
24# ntp = (ps: [ ps.ntplib ]);
25# };
26#
27# in ddAgentWithNtp = datadog-agent.overrideAttrs(_ : {
28# python = integrationsWithNtp.python;
29# });
30#
31# The NixOS module 'datadog-agent' provides a simplified interface to
32# this. Please see the module itself for more information.
33#
34# [1]: https://github.com/DataDog/integrations-core
35
36{
37 lib,
38 fetchFromGitHub,
39 python3Packages,
40 extraIntegrations ? { },
41}:
42
43let
44 inherit (lib) attrValues mapAttrs;
45
46 src = fetchFromGitHub {
47 owner = "DataDog";
48 repo = "integrations-core";
49 rev = version;
50 sha256 = "sha256-p5eoNNHQQl314mfUk2t3qQaerPu02GKA+tKkAY7bojk=";
51 };
52 version = "7.56.2";
53
54 # Build helper to build a single datadog integration package.
55 buildIntegration =
56 { pname, ... }@args:
57 python3Packages.buildPythonPackage (
58 args
59 // {
60 inherit src version;
61 name = "datadog-integration-${pname}-${version}";
62 pyproject = true;
63
64 sourceRoot = "${src.name}/${args.sourceRoot or pname}";
65 buildInputs = with python3Packages; [
66 hatchling
67 setuptools
68 ];
69 doCheck = false;
70 }
71 );
72
73 # Base package depended on by all other integrations.
74 datadog_checks_base = buildIntegration {
75 pname = "checks-base";
76 sourceRoot = "datadog_checks_base";
77
78 # Make setuptools build the 'base' and 'checks' modules.
79 postPatch = ''
80 substituteInPlace setup.py \
81 --replace "from setuptools import setup" "from setuptools import find_packages, setup" \
82 --replace "packages=['datadog_checks']" "packages=find_packages()"
83 '';
84
85 propagatedBuildInputs = with python3Packages; [
86 binary
87 cachetools
88 cryptography
89 immutables
90 jellyfish
91 prometheus-client
92 protobuf
93 pydantic
94 python-dateutil
95 pyyaml
96 requests
97 requests-toolbelt
98 requests-unixsocket
99 simplejson
100 uptime
101 wrapt
102 ];
103
104 pythonImportsCheck = [
105 "datadog_checks.base"
106 "datadog_checks.base.checks"
107 "datadog_checks.checks"
108 ];
109 };
110
111 # Default integrations that should be built:
112 defaultIntegrations = {
113 disk = (ps: [ ps.psutil ]);
114 mongo = (ps: [ ps.pymongo ]);
115 network = (ps: [ ps.psutil ]);
116 nginx = (ps: [ ]);
117 postgres = (
118 ps: with ps; [
119 pg8000
120 psycopg2
121 semver
122 ]
123 );
124 process = (ps: [ ps.psutil ]);
125 };
126
127 # All integrations (default + extra):
128 integrations = defaultIntegrations // extraIntegrations;
129 builtIntegrations = mapAttrs (
130 pname: fdeps:
131 buildIntegration {
132 inherit pname;
133 propagatedBuildInputs = (fdeps python3Packages) ++ [ datadog_checks_base ];
134 }
135 ) integrations;
136
137in
138builtIntegrations
139// {
140 inherit datadog_checks_base;
141 python = python3Packages.python.withPackages (_: (attrValues builtIntegrations));
142}