{ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; 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, ... }: { nixos-exporter = pkgs.rustPlatform.buildRustPackage rec { pname = "nixos-exporter"; version = "0.6.0"; src = ./.; nativeBuildInputs = [ pkgs.pkg-config ]; buildInputs = [ pkgs.openssl ]; cargoLock.lockFile = ./Cargo.lock; }; default = self.packages."${system}".nixos-exporter; }); apps = forAllSystems ({ pkgs, system, ... }: { nixos-exporter = { type = "app"; program = self.packages."${system}".nixos-exporter + "/bin/nixos-exporter"; }; nixos-validator = { type = "app"; program = self.packages."${system}".nixos-exporter + "/bin/nixos-validator"; }; default = self.apps."${system}".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 = { inherit (self) packages; }; }; }