Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NixOS Packaging #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ debian/files
debian/prometheus-mgit-exporter.debhelper.log
debian/prometheus-mgit-exporter.substvars
debian/prometheus-mgit-exporter/
prometheus-mgit-exporter
prometheus-mgit-exporter
result*
21 changes: 21 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ buildGoModule
, lib
}:

buildGoModule rec {
pname = "prometheus-mgit-exporter";
# get version from BUILD.bazel
version = with builtins; elemAt (match ".*version = \"([0-9.]*)\".*" (readFile ./BUILD.bazel)) 0;

src = ./.;

vendorHash = "sha256-q2e6Q8MbnpOguUNxTumpm3tGbBNes3ada9ma1agcTvs=";

meta = with lib; {
description = "A collection of useful monitoring for Prometheus by mgIT GmbH.";
homepage = "https://github.com/mgit-at/prometheus-mgit-exporter";
license = licenses.apsl20;
maintainers = with maintainers; [ mkg20001 ];
mainProgram = "prometheus-mgit-exporter";
};
}
44 changes: 44 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
description = "A collection of useful monitoring for Prometheus by mgIT GmbH.";

inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
inputs.patches4nixpkgs.url = "github:mgit-at/patches4nixpkgs/master";

outputs = { self, patches4nixpkgs, ... }@inputs:
let
patchPkgs = patches4nixpkgs.patch inputs.nixpkgs [ self ];
nixpkgs = patches4nixpkgs.eval patchPkgs;

supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system);
in
{
overlays.default = final: prev: {
prometheus-mgit-exporter = prev.callPackage ./. {};
};

patches4nixpkgs = nixpkgs: [
[
(! builtins.pathExists "${nixpkgs}/nixos/modules/services/monitoring/prometheus/mk-downstream-exporter.nix")
./nixos-prom-downstream.patch
]
];

packages = forAllSystems (system:
let
pkgs = (import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
});
in
{
inherit (pkgs) prometheus-mgit-exporter;
default = pkgs.prometheus-mgit-exporter;
}
);

nixosModules = {
prometheus-mgit-exporter = import ./module.nix;
};

checks = forAllSystems (system:
let
pkgs = (import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
});
in
{
prometheus-mgit-exporter = pkgs.testers.runNixOSTest (import ./test.nix);
}
);
};
}
159 changes: 159 additions & 0 deletions mgit-exporter.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
# nixpkgs/nixos/modules/services/prometheus/exporters/mgit.nix
{ config, lib, pkgs, options, utils, ... }:

with lib;

let
# for convenience we define cfg here
cfg = config.services.prometheus.exporters.mgit;
json = pkgs.formats.json {};
configurationFile = json.generate "config.json" cfg;
in
{
port = 9328; # The mgit exporter listens on this port by default

# `extraOpts` is an attribute set which contains additional options
# (and optional overrides for default options).
# Note that this attribute is optional.
extraOpts = {
listen = mkOption {
default = ":${toString cfg.port}";
type = types.str;
description = "Listening address";
};

certFile = {
enable = mkEnableOption "certificate file watching";
globs = mkOption {
default = [];
type = types.listOf types.str;
description = "List of globs";
};
exclude_system = mkOption {
type = types.bool;
description = "Exclude system certificates";
default = false;
};
};

mceLog = {
enable = mkEnableOption "MCE log";
path = mkOption {
default = "";
type = types.str;
description = "Path to MCE log";
};
};

ptHeartbeat = {
enable = mkEnableOption "PT heartbeat";
database = mkOption {
default = "";
type = types.str;
description = "Database for PT heartbeat";
};
table = mkOption {
default = "";
type = types.str;
description = "Table for PT heartbeat";
};
defaultsFile = mkOption {
default = "";
type = types.str;
description = "Defaults file for PT heartbeat";
};
masterId = mkOption {
default = 0;
type = types.int;
description = "Master ID for PT heartbeat";
};
};

fsTab = {
enable = mkEnableOption "fsTab";
};

binLog = {
enable = mkEnableOption "binLog";
path = mkOption {
default = "";
type = types.str;
description = "Path to binLog";
};
};

rasDaemon = {
enable = mkEnableOption "rasDaemon";
path = mkOption {
default = "";
type = types.str;
description = "Path to rasDaemon";
};
};

elk = {
enable = mkEnableOption "elk";
duration = mkOption {
default = "";
type = types.str;
description = "Duration for elk";
};
node = mkOption {
default = "default_node";
type = types.str;
description = "Node for elk";
};
};

exec = {
enable = mkEnableOption "exec";
scripts = mkOption {
default = {};
type = types.attrsOf (types.submodule ({ ... }: {
options = {
command = mkOption {
type = types.listOf types.str;
description = "Command";
};

dir = mkOption {
type = types.str;
description = "Working directory";
default = "";
};

timeout = mkOption {
type = types.str;
description = "Timeout";
default = "";
};
};
}));
description = "Scripts for exec";
};
};
};

# `serviceOpts` is an attribute set which contains configuration
# for the exporter's systemd service. One of
# `serviceOpts.script` and `serviceOpts.serviceConfig.ExecStart`
# has to be specified here. This will be merged with the default
# service configuration.
# Note that by default 'DynamicUser' is 'true'.
serviceOpts = {
unitConfig = {
Description = "mgIT exporter for Prometheus";
Documentation = "https://prometheus.io/docs/introduction/overview/";
};
serviceConfig = {
MemoryMax = "1G";
Restart = "on-failure";
RestartSec = 1;
DynamicUser = false;
ExecStart = utils.escapeSystemdExecArgs [
(getExe pkgs.prometheus-mgit-exporter)
"-config" (toString configurationFile)
];
};
};
}
8 changes: 8 additions & 0 deletions module.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ modulesPath, ... }: {
imports = [
(import "${modulesPath}/services/monitoring/prometheus/mk-downstream-exporter.nix" {
name = "mgit";
file = ./mgit-exporter.nix;
})
];
}
Loading