Merge pull request #8 from lucasbergman/nix-cleanup

Nix cleanup
This commit is contained in:
Jeremy Wall 2024-02-20 09:09:16 -05:00 committed by GitHub
commit 0abd67a729
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 116 additions and 136 deletions

View File

@ -1,11 +1,12 @@
let let
lock = builtins.fromJSON (builtins.readFile ./flake.lock); lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in in
(import ( (import (
fetchTarball { fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash; sha256 = lock.nodes.flake-compat.locked.narHash;
} }
) { ) {
src = ./.; src = ./.;
}).defaultNix })
.defaultNix

233
flake.nix
View File

@ -6,147 +6,126 @@
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
naersk.url = "github:nix-community/naersk"; naersk.url = "github:nix-community/naersk";
flake-compat = { url = github:edolstra/flake-compat; flake = false; }; flake-compat = {
flake-utils.url = "github:numtide/flake-utils"; url = github:edolstra/flake-compat;
flake = false;
};
flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = {nixpkgs, flake-utils, naersk, rust-overlay, ...}: outputs = {
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
]; ];
pkgs = import nixpkgs { inherit system overlays; }; pkgs = import nixpkgs {inherit system overlays;};
rust-bin = pkgs.rust-bin.stable."1.71.0".default; rust-bin = pkgs.rust-bin.stable."1.71.0".default;
naersk-lib = pkgs.callPackage naersk { naersk-lib = pkgs.callPackage naersk {
rustc = rust-bin; rustc = rust-bin;
cargo = rust-bin; cargo = rust-bin;
}; };
heracles = naersk-lib.buildPackage { heracles = naersk-lib.buildPackage {
name = "heracles"; name = "heracles";
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 (
with pkgs.darwin.apple_sdk.frameworks; [ Security SystemConfiguration ] if pkgs.stdenv.isDarwin
else then with pkgs.darwin.apple_sdk.frameworks; [Security SystemConfiguration]
[ pkgs.openssl ]) ++ [rust-bin]; else [pkgs.openssl]
)
++ [rust-bin];
}; };
in in {
{
packages.default = heracles; packages.default = heracles;
}) // { formatter = pkgs.alejandra;
nixosModule = {config, pkgs, lib}: with lib; { })
options = { // {
services.heracles.enable = mkEnableOption "enable heracles service"; nixosModules.default = {
services.heracles.listen = mkOption { config,
description = "[host]:port address for heracles to listen on"; pkgs,
default = "localhost:8080"; lib,
defaultText = "localhost:8080"; }: {
}; 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 = 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";
graphs = [
{
title = "Graph title";
query_type = "Range";
# yaxis formatting default for this graph
d3_tick_format = "~s";
plots = [
{ {
title = "A dashboard"; source = "http://heimdall:9001";
graphs = [ query = \'\'
{ sum by (instance)(irate(node_cpu_seconds_total{job="nodestats"}[5m]))
title = "Graph title"; \'\';
query_type = "Range"; meta = {
# yaxis formatting default for this graph name_function = "''${labels.instance}";
d3_tick_format = "~s"; named_axis = "y";
plots = [ # yaxis formatting for this subplot
{ d3_tick_format = "~s";
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 = '' # span for this graph.
[ span = {
{ end = "now";
title = "A dashboard"; duration = "1d";
graphs = [ step_duration = "10min";
{ };
title = "Graph title"; }
query_type = "Range"; ];
# yaxis formatting default for this graph # default span for dashboard
d3_tick_format = "~s"; span = {
plots = [ end = "now";
{ duration = "1d";
source = "http://heimdall:9001"; step_duration = "10min";
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 {
environment.etc."heracles.yaml" = {
text = (generators.toYAML {} config.services.heracles.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 ${config.services.heracles.listen} --config=${config.environment.etc."heracles.yaml".target}";
};
};
};
}; };
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}";
};
};
};
};
}; };
} }