i2pd-exporter/flake.nix

145 lines
3.9 KiB
Nix
Raw Normal View History

2024-05-20 00:47:07 +02:00
{
2024-05-21 00:16:36 +02:00
description = "i2pd-exporter devshell, service and options";
2024-05-20 00:47:07 +02:00
2024-05-21 00:16:36 +02:00
# Nixpkgs / NixOS version to use.
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
2024-05-20 00:47:07 +02:00
2024-05-21 00:16:36 +02:00
outputs = { self, nixpkgs }:
let
#version = builtins.substring 0 8 self.lastModifiedDate;
# System types to support.
supportedSystems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs {
inherit system;
});
in
{
packages = forAllSystems (system:
let
pkgs = nixpkgsFor.${system};
in
{
default = pkgs.rustPlatform.buildRustPackage {
pname = "i2pd-exporter";
version = "0.1.1";
src = ./.;
nativeBuildInputs = with pkgs; [
pkg-config
openssl
];
buildInputs = with pkgs; [
pkg-config
openssl
];
cargoLock.lockFile = ./Cargo.lock;
};
});
nixosModules.default = { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.prometheus.exporters.i2pd;
in
{
# todo rename lib.mdoc
2024-05-21 00:16:36 +02:00
options.services.prometheus.exporters.i2pd = {
enable = mkEnableOption "Enable the i2pd exporter";
listenAddress = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
What address the exporter should listen to.
'';
2024-05-21 00:16:36 +02:00
};
port = mkOption {
type = types.port;
default = 5733;
description = ''
What port the exporter should listen on.
'';
2024-05-21 00:16:36 +02:00
};
routerAddress = mkOption {
type = types.str;
default = "http://127.0.0.1:7650";
description = ''
The endpoint of the router's i2pcontrol protocol. ! Has to be https
'';
2024-05-20 00:47:07 +02:00
};
2024-05-21 00:16:36 +02:00
openFirewall = mkOption {
type = types.bool;
default = false;
description = ''
2024-05-21 00:16:36 +02:00
Open the appropriate ports in the firewall for i2pd-exporter.
'';
};
routerPassword = mkOption {
type = types.str;
default = "itoopie";
description = ''
The password for the i2pcontrol endpoint, by default itoopie
'';
2024-05-21 00:16:36 +02:00
};
};
config = mkIf cfg.enable {
systemd.services.i2pd-exporter = {
description = "Exporter for i2pd";
wantedBy = [ "multi-user.target" ];
environment = {
IP = cfg.listenAddress;
PORT = toString cfg.port;
ROUTER = cfg.routerAddress;
PASSWORD = cfg.routerPassword;
};
serviceConfig = {
DynamicUser = "yes";
ExecStart = "${self.packages.${pkgs.system}.default}/bin/i2pd-exporter";
Restart = "on-failure";
RestartSec = "5s";
};
2024-05-21 00:16:36 +02:00
};
networking.firewall =
mkIf cfg.openFirewall { allowedTCPPorts = [ cfg.port ] ++ optional (cfg.listenAddress != "127.0.0.1") cfg.port; };
};
};
devShells.default =
with nixpkgs; mkShell
{
LIBCLANG_PATH = "${pkgs.llvmPackages_17.libclang.lib}/lib";
RUST_BACKTRACE = 1;
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
packages = with pkgs; [
rustc
cargo
rustfmt
rust-analyzer
clippy
rustup
pkg-config
openssl
];
2024-05-20 00:47:07 +02:00
};
2024-05-21 00:16:36 +02:00
};
2024-05-20 00:47:07 +02:00
}
2024-05-21 00:16:36 +02:00