0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

netdata module: add automatic claim

Allow machines to auto-register themselves by passing the claim token.
This commit is contained in:
zimbatm 2023-04-27 10:30:29 +02:00
parent f2c3d5f5cf
commit f4d5a76a81

View file

@ -159,6 +159,15 @@ in {
'';
};
claim_token_file = mkOption {
type = types.nullOr types.path;
default = null;
description = lib.mdDoc ''
If set, automatically registers the agent using the given claim token
file.
'';
};
enableAnalyticsReporting = mkOption {
type = types.bool;
default = false;
@ -246,7 +255,25 @@ in {
PrivateTmp = true;
ProtectControlGroups = true;
PrivateMounts = true;
};
} // (lib.optionalAttrs (cfg.claim_token_file != null) {
LoadCredential = [
"netdata_claim_token:${cfg.claim_token_file}"
];
ExecStartPre = pkgs.writeShellScript "netdata-claim" ''
set -euo pipefail
if [[ -f /var/lib/netdata/cloud.d/claimed_id ]]; then
# Already registered
exit
fi
exec ${cfg.package}/bin/netdata-claim.sh \
-token="$(< "$CREDENTIALS_DIRECTORY/netdata_claim_token")" \
-url=https://app.netdata.cloud \
-daemon-not-running
'';
});
};
systemd.enableCgroupAccounting = true;