Compare commits

..

No commits in common. "0abd67a729ae4d9baf5ffd2a190c8f330a15caa6" and "847413f4f586ddf24d8dfed4cc43826b58301784" have entirely different histories.

2 changed files with 136 additions and 116 deletions

View File

@ -8,5 +8,4 @@ in
} }
) { ) {
src = ./.; src = ./.;
}) }).defaultNix
.defaultNix

103
flake.nix
View File

@ -6,20 +6,11 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
naersk.url = "github:nix-community/naersk"; naersk.url = "github:nix-community/naersk";
flake-compat = { flake-compat = { url = github:edolstra/flake-compat; flake = false; };
url = github:edolstra/flake-compat;
flake = false;
};
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { outputs = {nixpkgs, flake-utils, naersk, rust-overlay, ...}:
nixpkgs,
flake-utils,
naersk,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
overlays = [ overlays = [
rust-overlay.overlays.default rust-overlay.overlays.default
@ -35,38 +26,67 @@
verion = "0.0.1"; verion = "0.0.1";
src = ./.; src = ./.;
nativeBuildInputs = [ pkgs.pkg-config ]; nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = buildInputs = (
( if pkgs.stdenv.isDarwin then
if pkgs.stdenv.isDarwin with pkgs.darwin.apple_sdk.frameworks; [ Security SystemConfiguration ]
then with pkgs.darwin.apple_sdk.frameworks; [Security SystemConfiguration] else
else [pkgs.openssl] [ pkgs.openssl ]) ++ [rust-bin];
)
++ [rust-bin];
}; };
in { in
{
packages.default = heracles; packages.default = heracles;
formatter = pkgs.alejandra; }) // {
}) nixosModule = {config, pkgs, lib}: with lib; {
// {
nixosModules.default = {
config,
pkgs,
lib,
}: {
options = { options = {
services.heracles.enable = lib.mkEnableOption "enable heracles service"; services.heracles.enable = mkEnableOption "enable heracles service";
services.heracles.listen = lib.mkOption { services.heracles.listen = mkOption {
description = "[host]:port address for heracles to listen on"; description = "[host]:port address for heracles to listen on";
default = "localhost:8080"; default = "localhost:8080";
defaultText = "localhost:8080"; defaultText = "localhost:8080";
type = lib.types.string;
}; };
services.heracles.settings = lib.mkOption { services.heracles.settings = mkOption {
description = "heracles dashboard Configuration"; description = "heracles dashboard Configuration";
type = lib.types.listOf lib.types.attrs; default = [
default = []; {
defaultText = lib.literalExpression '' title = "A dashboard";
graphs = [
{
title = "Graph title";
query_type = "Range";
# yaxis formatting default for this graph
d3_tick_format = "~s";
plots = [
{
source = "http://heimdall:9001";
query = ''
sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
'';
meta = {
name_function = "`\${labels.instance}`";
named_axis = "y";
# yaxis formatting for this subplot
d3_tick_format = "~s";
};
}
];
# span for this graph.
span = {
end = "now";
duration = "1d";
step_duration = "10min";
};
}
];
# default span for dashboard
span = {
end = "now";
duration = "1d";
step_duration = "10min";
};
}
];
defaultText = ''
[ [
{ {
title = "A dashboard"; title = "A dashboard";
@ -83,7 +103,9 @@
sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m])) sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
\'\'; \'\';
meta = { meta = {
name_function = "''${labels.instance}"; name_label = "instance";
name_prefix = "trace name prefix";
name_suffix = "trace name suffix";
named_axis = "y"; named_axis = "y";
# yaxis formatting for this subplot # yaxis formatting for this subplot
d3_tick_format = "~s"; d3_tick_format = "~s";
@ -110,11 +132,10 @@
}; };
}; };
config = let config = mkIf config.services.heracles.enable {
cfg = config.services.heracles; environment.etc."heracles.yaml" = {
cfgFile = pkgs.writeText "heracles.yaml" (builtins.toJSON cfg.settings); text = (generators.toYAML {} config.services.heracles.settings);
in };
lib.mkIf cfg.enable {
systemd.services.heracles = { systemd.services.heracles = {
wantedBy = [ "multi-user.target" "default.target" ]; wantedBy = [ "multi-user.target" "default.target" ];
wants = [ "network.target" ]; wants = [ "network.target" ];
@ -122,7 +143,7 @@
serviceConfig = { serviceConfig = {
Restart = "on-failure"; Restart = "on-failure";
RestartSec = "30s"; RestartSec = "30s";
ExecStart = "${pkgs.heracles}/bin/heracles --listen ${cfg.listen} --config=${cfgFile}"; ExecStart = "${pkgs.heracles}/bin/heracles --listen ${config.services.heracles.listen} --config=${config.environment.etc."heracles.yaml".target}";
}; };
}; };
}; };