This commit is contained in:
Astro 2022-12-17 00:46:29 +01:00
parent 3dc05fb224
commit 406df31b9b
3 changed files with 177 additions and 0 deletions

65
flake.lock Normal file
View File

@ -0,0 +1,65 @@
{
"nodes": {
"naersk": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1671096816,
"narHash": "sha256-ezQCsNgmpUHdZANDCILm3RvtO1xH8uujk/+EqNvzIOg=",
"owner": "nix-community",
"repo": "naersk",
"rev": "d998160d6a076cfe8f9741e56aeec7e267e3e114",
"type": "github"
},
"original": {
"owner": "nix-community",
"ref": "master",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1671190014,
"narHash": "sha256-NW385LW4Nj53Hbv3LXr458s4NL2/wcARC8rzK7vSWkw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fbcb61bd7eb19914cbd88789c3586a63ff46b72b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

66
flake.nix Normal file
View File

@ -0,0 +1,66 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
naersk = {
url = "github:nix-community/naersk/master";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, utils, naersk }:
let
inherit (nixpkgs) lib;
makeAlert2muc = pkgs:
let
naersk-lib = pkgs.callPackage naersk { };
in
naersk-lib.buildPackage {
pname = "alert2muc";
root = ./.;
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl systemd ];
checkInputs = [ pkgs.rustPackages.clippy ];
doCheck = true;
cargoTestCommands = x:
x ++ [
''cargo clippy --all --all-features --tests -- \
-D clippy::pedantic \
-D warnings \
-A clippy::module-name-repetitions \
-A clippy::too-many-lines \
-A clippy::cast-possible-wrap \
-A clippy::cast-possible-truncation \
-A clippy::nonminimal_bool''
];
meta.description = "Send Prometheus alerts to XMPP Multi-User Chatrooms";
};
in
utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
packages = {
default = self.packages."${system}".alert2muc;
alert2muc = makeAlert2muc pkgs;
};
apps.default = utils.lib.mkApp {
drv = self.packages."${system}".default;
};
devShells.default = with pkgs; mkShell {
nativeBuildInputs = [ cargo rustc rustfmt rustPackages.clippy rust-analyzer ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
};
})
// {
overlays.default = (_: prev: {
alert2muc = makeAlert2muc prev;
});
nixosModules.default = ./nixos-module.nix { inherit self; };
};
}

46
nixos-module.nix Normal file
View File

@ -0,0 +1,46 @@
{ self }:
{ config, lib, pkgs, ... }: {
options.services.alert2muc = with lib; {
enable = mkEnableOption "Enable Prometheus XMPP MUC bot";
configFile = mkOption {
type = types.str;
};
user = mkOption {
type = types.str;
default = "alert2muc";
};
group = mkOption {
type = types.str;
default = "alert2muc";
};
};
config =
let
cfg = config.services.alert2muc;
in
lib.mkIf cfg.enable {
users = {
users.${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
groups.${cfg.group} = {};
};
systemd.services.alert2muc = {
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
serviceConfig = {
Type = "notify";
ExecStart = "${self.packages.${pkgs.system}.alert2muc}/bin/alert2muc ${lib.escapeShellArg cfg.configFile}";
User = cfg.user;
Group = cfg.group;
ProtectSystem = "full";
Restart = "always";
RestartSec = "10s";
WatchdogSec = "3600s";
};
};
};
}