1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 cfg = config.services.blackfire-agent;
10
11 agentConfigFile = lib.generators.toINI { } {
12 blackfire = cfg.settings;
13 };
14
15 agentSock = "blackfire/agent.sock";
16in
17{
18 meta = {
19 maintainers = pkgs.blackfire.meta.maintainers;
20 doc = ./blackfire.md;
21 };
22
23 options = {
24 services.blackfire-agent = {
25 enable = lib.mkEnableOption "Blackfire profiler agent";
26 settings = lib.mkOption {
27 description = ''
28 See https://blackfire.io/docs/up-and-running/configuration/agent
29 '';
30 type = lib.types.submodule {
31 freeformType = with lib.types; attrsOf str;
32
33 options = {
34 server-id = lib.mkOption {
35 type = lib.types.str;
36 description = ''
37 Sets the server id used to authenticate with Blackfire
38
39 You can find your personal server-id at https://blackfire.io/my/settings/credentials
40 '';
41 };
42
43 server-token = lib.mkOption {
44 type = lib.types.str;
45 description = ''
46 Sets the server token used to authenticate with Blackfire
47
48 You can find your personal server-token at https://blackfire.io/my/settings/credentials
49 '';
50 };
51 };
52 };
53 };
54 };
55 };
56
57 config = lib.mkIf cfg.enable {
58 environment.etc."blackfire/agent".text = agentConfigFile;
59
60 services.blackfire-agent.settings.socket = "unix:///run/${agentSock}";
61
62 systemd.packages = [
63 pkgs.blackfire
64 ];
65 };
66}