-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
136 lines (133 loc) · 4.15 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
inputs = {
nixpkgs.url = "nixpkgs";
rust-overlay = {
url = "github:oxalica/rust-overlay?ref=stable";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk.url = "github:nix-community/naersk";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
nixpkgs,
flake-utils,
naersk,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
overlays = [
rust-overlay.overlays.default
];
pkgs = import nixpkgs {inherit system overlays;};
rust-bin = pkgs.rust-bin.stable."1.71.0".default;
naersk-lib = pkgs.callPackage naersk {
rustc = rust-bin;
cargo = rust-bin;
};
heracles = naersk-lib.buildPackage {
name = "heracles";
verion = "0.0.1";
src = ./.;
nativeBuildInputs = [pkgs.pkg-config];
buildInputs =
(
if pkgs.stdenv.isDarwin
then with pkgs.darwin.apple_sdk.frameworks; [Security SystemConfiguration]
else [pkgs.openssl]
)
++ [rust-bin];
};
in {
packages.default = heracles;
formatter = pkgs.alejandra;
})
// {
nixosModules.default = {
config,
pkgs,
lib,
...
}: {
options = {
services.heracles.enable = lib.mkEnableOption "enable heracles service";
services.heracles.listen = lib.mkOption {
description = "[host]:port address for heracles to listen on";
default = "localhost:8080";
defaultText = "localhost:8080";
type = lib.types.string;
};
services.heracles.settings = lib.mkOption {
description = "heracles dashboard Configuration";
type = lib.types.listOf lib.types.attrs;
default = [];
defaultText = lib.literalExpression ''
[
{
title = "A dashboard";
graphs = [
{
title = "Graph title";
query_type = "Range";
# yaxis formatting default for this graph
d3_tick_format = "~s";
yaxes = [
{
tickformat = "~s";
}
];
plots = [
{
source = "http://heimdall:9001";
query = \'\'
sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
\'\';
meta = {
name_function = "''${labels.instance}";
# yaxis to use for this plot
yaxis = "y";
};
}
];
# span for this graph.
span = {
end = "now";
duration = "1d";
step_duration = "10min";
};
}
];
# default span for dashboard
span = {
end = "now";
duration = "1d";
step_duration = "10min";
};
}
]
'';
};
};
config = let
cfg = config.services.heracles;
cfgFile = pkgs.writeText "heracles.yaml" (builtins.toJSON cfg.settings);
in
lib.mkIf cfg.enable {
systemd.services.heracles = {
wantedBy = ["multi-user.target" "default.target"];
wants = ["network.target"];
after = ["network-online.target"];
serviceConfig = {
Restart = "on-failure";
RestartSec = "30s";
ExecStart = "${pkgs.heracles}/bin/heracles --listen ${cfg.listen} --config=${cfgFile}";
};
};
};
};
};
}