2022-12-31 01:01:22 +01:00
|
|
|
{
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
|
|
};
|
2024-08-25 14:37:20 +02:00
|
|
|
outputs = { self, nixpkgs, ... }: let
|
|
|
|
forAllSystems = f: (nixpkgs.lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] (system: let
|
|
|
|
pkgs = import nixpkgs { inherit system; };
|
|
|
|
in f { inherit pkgs system; } ));
|
|
|
|
in {
|
|
|
|
packages = forAllSystems ({ pkgs, system, ... }: {
|
2022-12-31 01:01:22 +01:00
|
|
|
nixos-exporter = pkgs.rustPlatform.buildRustPackage rec {
|
|
|
|
pname = "nixos-exporter";
|
2023-05-09 11:45:33 +02:00
|
|
|
version = "0.6.0";
|
2022-12-31 01:01:22 +01:00
|
|
|
|
|
|
|
src = ./.;
|
|
|
|
|
2023-01-08 18:05:28 +01:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkgs.pkg-config
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
pkgs.openssl
|
|
|
|
];
|
|
|
|
|
2022-12-31 01:01:22 +01:00
|
|
|
cargoLock.lockFile = ./Cargo.lock;
|
|
|
|
|
|
|
|
};
|
2024-08-25 14:37:20 +02:00
|
|
|
default = self.packages."${system}".nixos-exporter;
|
|
|
|
});
|
2022-12-31 01:01:22 +01:00
|
|
|
|
2024-08-25 14:37:20 +02:00
|
|
|
apps = forAllSystems ({ pkgs, system, ... }: {
|
2022-12-31 01:01:22 +01:00
|
|
|
nixos-exporter = {
|
|
|
|
type = "app";
|
2024-08-25 14:37:20 +02:00
|
|
|
program = self.packages."${system}".nixos-exporter + "/bin/nixos-exporter";
|
2022-12-31 01:01:22 +01:00
|
|
|
};
|
2023-05-09 11:45:33 +02:00
|
|
|
nixos-validator = {
|
|
|
|
type = "app";
|
2024-08-25 14:37:20 +02:00
|
|
|
program = self.packages."${system}".nixos-exporter + "/bin/nixos-validator";
|
2023-05-09 11:45:33 +02:00
|
|
|
};
|
2024-08-25 14:37:20 +02:00
|
|
|
default = self.apps."${system}".nixos-exporter;
|
|
|
|
});
|
2022-12-31 01:01:22 +01:00
|
|
|
|
2023-05-09 11:45:33 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-12-31 01:01:22 +01:00
|
|
|
hydraJobs = {
|
2024-08-25 14:37:20 +02:00
|
|
|
inherit (self)
|
|
|
|
packages;
|
2022-12-31 01:01:22 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|