mirror of
https://github.com/zaphar/Heracles.git
synced 2025-07-23 12:39:50 -04:00
maint: Some Nix flake cleanups
Specifically: 1. Switch from the nixosModule flake output (which is deprecated) to nixosModules.default 2. Remove "with lib;" it's convenient, but I've gotten feedback when upstreaming module changes that that shouldn't be a thing in nixpkgs anymore 3. Add a little type checking to the NixOS module options 4. Switch the default config to empty (but leave the example) 5. Use the convention "let cfg = config.services.heracles," a thing that's super common in NixOS
This commit is contained in:
parent
63b4f810c2
commit
668015ed17
94
flake.nix
94
flake.nix
@ -48,23 +48,26 @@
|
|||||||
formatter = pkgs.alejandra;
|
formatter = pkgs.alejandra;
|
||||||
})
|
})
|
||||||
// {
|
// {
|
||||||
nixosModule = {
|
nixosModules.default = {
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
}:
|
}: {
|
||||||
with 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 = mkOption {
|
services.heracles.settings = lib.mkOption {
|
||||||
description = "heracles dashboard Configuration";
|
description = "heracles dashboard Configuration";
|
||||||
default = [
|
type = lib.types.listOf lib.types.attrs;
|
||||||
|
default = [];
|
||||||
|
defaultText = lib.literalExpression ''
|
||||||
|
[
|
||||||
{
|
{
|
||||||
title = "A dashboard";
|
title = "A dashboard";
|
||||||
graphs = [
|
graphs = [
|
||||||
@ -76,11 +79,11 @@
|
|||||||
plots = [
|
plots = [
|
||||||
{
|
{
|
||||||
source = "http://heimdall:9001";
|
source = "http://heimdall:9001";
|
||||||
query = ''
|
query = \'\'
|
||||||
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_function = "''${labels.instance}";
|
||||||
named_axis = "y";
|
named_axis = "y";
|
||||||
# yaxis formatting for this subplot
|
# yaxis formatting for this subplot
|
||||||
d3_tick_format = "~s";
|
d3_tick_format = "~s";
|
||||||
@ -102,56 +105,17 @@
|
|||||||
step_duration = "10min";
|
step_duration = "10min";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
defaultText = ''
|
'';
|
||||||
[
|
|
||||||
{
|
|
||||||
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_label = "instance";
|
|
||||||
name_prefix = "trace name prefix";
|
|
||||||
name_suffix = "trace name suffix";
|
|
||||||
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";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
]
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config = mkIf config.services.heracles.enable {
|
config = let
|
||||||
|
cfg = config.services.heracles;
|
||||||
|
in
|
||||||
|
lib.mkIf cfg.enable {
|
||||||
environment.etc."heracles.yaml" = {
|
environment.etc."heracles.yaml" = {
|
||||||
text = generators.toYAML {} config.services.heracles.settings;
|
text = lib.generators.toYAML {} cfg.settings;
|
||||||
};
|
};
|
||||||
systemd.services.heracles = {
|
systemd.services.heracles = {
|
||||||
wantedBy = ["multi-user.target" "default.target"];
|
wantedBy = ["multi-user.target" "default.target"];
|
||||||
@ -160,10 +124,10 @@
|
|||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "30s";
|
RestartSec = "30s";
|
||||||
ExecStart = "${pkgs.heracles}/bin/heracles --listen ${config.services.heracles.listen} --config=${config.environment.etc."heracles.yaml".target}";
|
ExecStart = "${pkgs.heracles}/bin/heracles --listen ${cfg.listen} --config=${config.environment.etc."heracles.yaml".target}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user