Heracles/flake.nix

134 lines
4.1 KiB
Nix
Raw Normal View History

2024-02-17 20:49:03 -05:00
{
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";
2024-02-17 20:49:03 -05:00
};
outputs = {
nixpkgs,
flake-utils,
naersk,
rust-overlay,
...
}:
2024-02-17 20:49:03 -05:00
flake-utils.lib.eachDefaultSystem (system: let
overlays = [
rust-overlay.overlays.default
];
pkgs = import nixpkgs {inherit system overlays;};
2024-02-17 20:49:03 -05:00
rust-bin = pkgs.rust-bin.stable."1.71.0".default;
naersk-lib = pkgs.callPackage naersk {
rustc = rust-bin;
cargo = rust-bin;
2024-02-17 20:49:03 -05:00
};
2024-02-19 16:56:14 -05:00
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];
2024-02-17 20:49:03 -05:00
};
in {
2024-02-19 16:56:14 -05:00
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;
};
2024-02-19 16:56:14 -05:00
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";
plots = [
2024-02-19 16:56:14 -05:00
{
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";
};
2024-02-19 16:56:14 -05:00
}
];
# span for this graph.
span = {
end = "now";
duration = "1d";
step_duration = "10min";
};
}
];
# default span for dashboard
span = {
end = "now";
duration = "1d";
step_duration = "10min";
};
}
]
'';
};
};
2024-02-19 16:56:14 -05:00
config = let
cfg = config.services.heracles;
in
lib.mkIf cfg.enable {
environment.etc."heracles.yaml" = {
text = lib.generators.toYAML {} cfg.settings;
};
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=${config.environment.etc."heracles.yaml".target}";
};
2024-02-19 16:56:14 -05:00
};
};
};
2024-02-19 16:56:14 -05:00
};
2024-02-17 20:49:03 -05:00
}