{ description = "i2pd-exporter devshell, service and options"; # Nixpkgs / NixOS version to use. inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; 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 { options.services.prometheus.exporters.i2pd = { enable = mkEnableOption "Enable the i2pd exporter"; listenAddress = mkOption { type = types.str; default = "127.0.0.1"; }; port = mkOption { type = types.port; default = 5733; }; routerAddress = mkOption { type = types.str; default = "http://127.0.0.1:7650"; }; openFirewall = mkOption { type = types.bool; default = false; description = lib.mdDoc '' Open the appropriate ports in the firewall for i2pd-exporter. ''; }; routerPassword = mkOption { type = types.str; default = "itoopie"; }; }; 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"; }; }; 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 ]; }; }; }