1
0

Bump version and add modules

This commit is contained in:
clerie 2023-05-09 11:45:33 +02:00
parent e27202d63b
commit 5e86139ee4
3 changed files with 132 additions and 3 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
result

2
Cargo.lock generated
View File

@ -450,7 +450,7 @@ dependencies = [
[[package]] [[package]]
name = "nixos-exporter" name = "nixos-exporter"
version = "0.5.0" version = "0.6.0"
dependencies = [ dependencies = [
"axum", "axum",
"reqwest", "reqwest",

132
flake.nix
View File

@ -10,7 +10,7 @@
in { in {
nixos-exporter = pkgs.rustPlatform.buildRustPackage rec { nixos-exporter = pkgs.rustPlatform.buildRustPackage rec {
pname = "nixos-exporter"; pname = "nixos-exporter";
version = "0.5.0"; version = "0.6.0";
src = ./.; src = ./.;
@ -33,12 +33,140 @@
type = "app"; type = "app";
program = self.packages.x86_64-linux.nixos-exporter + "/bin/nixos-exporter"; program = self.packages.x86_64-linux.nixos-exporter + "/bin/nixos-exporter";
}; };
nixos-validator = {
type = "app";
program = self.packages.x86_64-linux.nixos-exporter + "/bin/nixos-validator";
};
default = self.apps.x86_64-linux.nixos-exporter; default = self.apps.x86_64-linux.nixos-exporter;
}; };
nixosModules = {
nixos-exporter = { config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.nixos-exporter;
in {
options = {
services.nixos-exporter = {
enable = mkEnableOption "Export NixOS status metrics";
listen = mkOption {
type = with types; nullOr str;
default = null;
description = "Interface for metrics";
example = "[::]:2345";
};
};
};
config = mkIf cfg.enable {
users.users."nixos-exporter" = {
isSystemUser = true;
group = "nixos-exporter";
};
users.groups."nixos-exporter" = {};
systemd.services."nixos-exporter" = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Restart = "always";
PrivateTmp = true;
WorkingDirectory = "/tmp";
RuntimeDirectory = "nixos-exporter";
User = "nixos-exporter";
Group = "nixos-exporter";
ExecStart = ''
${self.packages."${config.nixpkgs.system}".nixos-exporter}/bin/nixos-exporter ${optionalString (cfg.listen != null) "--listen ${escapeShellArg cfg.listen}"}
'';
};
};
};
};
nixos-validator = { config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.nixos-validator;
in {
options = {
services.nixos-validator = {
enable = mkEnableOption "Validate NixOS metrics";
listen = mkOption {
type = with types; nullOr str;
default = null;
description = "Interface for metrics";
example = "[::]:2345";
};
prometheusUrl = mkOption {
type = types.str;
description = "Url for Prometheus";
example = "https://prometheus.monitoring.clerie.de";
};
prometheusQueryTagTemplate = mkOption {
type = with types; nullOr str;
default = null;
description = "Template for Prometheus Query";
example = "instance=\"{}\"";
};
hydraUrl = mkOption {
type = types.str;
description = "Url for Hydra";
example = "https://hydra.clerie.de";
};
hydraJobTemplate = mkOption {
type = with types; nullOr str;
default = null;
description = "Template for Hydra Job Url";
example = "nixfiles/nixfiles/nixosConfigurations.{}";
};
};
};
config = mkIf cfg.enable {
users.users."nixos-validator" = {
isSystemUser = true;
group = "nixos-validator";
};
users.groups."nixos-validator" = {};
systemd.services."nixos-validator" = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
Restart = "always";
PrivateTmp = true;
WorkingDirectory = "/tmp";
RuntimeDirectory = "nixos-validator";
User = "nixos-validator";
Group = "nixos-validator";
ExecStart = ''
${self.packages."${config.nixpkgs.system}".nixos-exporter}/bin/nixos-validator ${concatStringsSep " " [
(optionalString (cfg.listen != null) "--listen ${escapeShellArg cfg.listen}")
"--prometheus-url ${escapeShellArg cfg.prometheusUrl}"
(optionalString (cfg.prometheusQueryTagTemplate != null) "--prometheus-query-tag-template ${escapeShellArg cfg.prometheusQueryTagTemplate}")
"--hydra-url ${escapeShellArg cfg.hydraUrl}"
(optionalString (cfg.hydraJobTemplate != null) "--hydra-job-template ${escapeShellArg cfg.hydraJobTemplate}")
]}
'';
};
};
};
};
default = { ... }:
{
imports = [
self.nixosModules.nixos-exporter
self.nixosModules.nixos-validator
];
};
};
hydraJobs = { hydraJobs = {
packages.x86_64-linux.nixos-exporter = self.packages.x86_64-linux.nixos-exporter; packages.x86_64-linux.nixos-exporter = self.packages.x86_64-linux.nixos-exporter;
}; };
}; };
} }