Skip to content

Commit 809b7ae

Browse files
committed
config(modules): Add cachix-deploy-metrics module
1 parent 5e741ac commit 809b7ae

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{ withSystem, ... }:
2+
{
3+
flake.modules.nixos.cachix-deploy-metrics =
4+
{
5+
pkgs,
6+
config,
7+
lib,
8+
...
9+
}:
10+
let
11+
inherit (lib)
12+
types
13+
mkEnableOption
14+
mkOption
15+
mkIf
16+
concatMapStringsSep
17+
;
18+
cfg = config.services.cachix-deploy-metrics;
19+
defaultPackage = withSystem pkgs.stdenv.hostPlatform.system (
20+
{ config, ... }: config.packages.cachix-deploy-metrics
21+
);
22+
in
23+
{
24+
options.services.cachix-deploy-metrics = with lib; {
25+
enable = mkEnableOption (lib.mdDoc "Cachix Deploy Metrics");
26+
27+
package = mkOption {
28+
type = types.package;
29+
default = defaultPackage;
30+
description = "Package providing the deploy-metrics binary.";
31+
};
32+
33+
scrape-interval = mkOption {
34+
type = types.int;
35+
default = 1;
36+
description = "Scrape interval in seconds.";
37+
};
38+
39+
auth-token-path = mkOption {
40+
type = types.path;
41+
description = "Cachix auth token path.";
42+
};
43+
44+
workspace = mkOption {
45+
type = types.str;
46+
description = "Cachix workspace.";
47+
};
48+
49+
agent-names = mkOption {
50+
type = types.listOf types.str;
51+
default = [ ];
52+
description = "List of Cachix deploy agents.";
53+
example = [
54+
"machine-01"
55+
"machine-02"
56+
];
57+
};
58+
59+
port = mkOption {
60+
type = types.port;
61+
default = 9160;
62+
description = "Port number of Cachix Deployments Exporter service.";
63+
};
64+
};
65+
66+
config = mkIf cfg.enable {
67+
systemd.services.cachix-deploy-metrics = {
68+
description = "Prometheus exporter for Cachix Deploy";
69+
wantedBy = [ "multi-user.target" ];
70+
path = [ cfg.package ];
71+
serviceConfig = {
72+
ExecStart = ''
73+
${lib.getExe cfg.package} \
74+
--port ${toString cfg.port} \
75+
--scrape-interval ${toString cfg.scrape-interval} \
76+
--auth-token-path ${cfg.auth-token-path} \
77+
--workspace ${cfg.workspace} \
78+
${
79+
if cfg.agent-names == [ ] then
80+
""
81+
else
82+
concatMapStringsSep " \\\n" (agent: "--agent-names=${agent}") cfg.agent-names
83+
}
84+
'';
85+
Restart = "on-failure";
86+
RestartSec = 10;
87+
};
88+
};
89+
};
90+
};
91+
}

modules/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
imports = [
3+
./cachix-deploy-metrics
34
./lido
45
./pyroscope
56
./folder-size-metrics

0 commit comments

Comments
 (0)