flake finished

This commit is contained in:
2005 2024-05-21 00:16:36 +02:00
parent f9a8ce41dd
commit 62631bcae4
4 changed files with 128 additions and 164 deletions

2
Cargo.lock generated
View file

@ -733,7 +733,7 @@ dependencies = [
] ]
[[package]] [[package]]
name = "i2pdmetrics" name = "i2pd-exporter"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"async-std", "async-std",

View file

@ -1,5 +1,5 @@
[package] [package]
name = "i2pdmetrics" name = "i2pd-exporter"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"

View file

@ -1,119 +1,24 @@
{ {
"nodes": { "nodes": {
"advisory-db": {
"flake": false,
"locked": {
"lastModified": 1714183630,
"narHash": "sha256-1BVft7ggSN2XXFeXQjazU3jN9wVECd9qp2mZx/8GDMk=",
"owner": "rustsec",
"repo": "advisory-db",
"rev": "35e7459a331d3e0c585e56dabd03006b9b354088",
"type": "github"
},
"original": {
"owner": "rustsec",
"repo": "advisory-db",
"type": "github"
}
},
"crane": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1716155989,
"narHash": "sha256-waAI5EvvISkQyw44awtrzdzqTVKsrSLbgiUHP6RM6BE=",
"owner": "ipetkov",
"repo": "crane",
"rev": "b7a1655564f96c28fa4c7a0d4888034c47f5ceb0",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": []
},
"locked": {
"lastModified": 1716099865,
"narHash": "sha256-GrNswS37mF+Jj/GNb2uNapd11sR9IWf7j9WexybunPs=",
"owner": "nix-community",
"repo": "fenix",
"rev": "f7737feef42fa8abe70de20b9a13b845a113cfeb",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1716128955, "lastModified": 1716137900,
"narHash": "sha256-3DNg/PV+X2V7yn8b/fUR2ppakw7D9N4sjVBGk6nDwII=", "narHash": "sha256-sowPU+tLQv8GlqtVtsXioTKeaQvlMz/pefcdwg8MvfM=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "f9256de8281f2ccd04985ac5c30d8f69aefadbe8", "rev": "6c0b7a92c30122196a761b440ac0d46d3d9954f1",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "id": "nixpkgs",
"ref": "nixpkgs-unstable", "ref": "nixos-unstable",
"repo": "nixpkgs", "type": "indirect"
"type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

131
flake.nix
View file

@ -1,35 +1,60 @@
{ {
inputs = { description = "i2pd-exporter devshell, service and options";
naersk.url = "github:nix-community/naersk/master";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, utils, naersk }: # Nixpkgs / NixOS version to use.
utils.lib.eachDefaultSystem (system: inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let let
pkgs = import nixpkgs { inherit system; }; #version = builtins.substring 0 8 self.lastModifiedDate;
naersk-lib = pkgs.callPackage naersk { };
# 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 in
{ {
defaultPackage = naersk-lib.buildPackage ./.;
devShell = with pkgs; mkShell {
buildInputs = [ cargo rustc rustfmt pre-commit rustPackages.clippy ];
RUST_SRC_PATH = rustPlatform.rustLibSrc;
# todo add rust for vscodium
};
packages = forAllSystems (system:
nixosModules.default = let
{ pkgs, config, lib, ... }: pkgs = nixpkgsFor.${system};
in
{ {
options = { default = pkgs.rustPlatform.buildRustPackage {
services.i2pd-exporter = with lib; { pname = "i2pd-exporter";
version = "0.1.1";
src = ./.;
enable = mkEnableOption "i2pd-exporter"; 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 { listenAddress = mkOption {
type = with types; nullOr str; type = types.str;
default = "127.0.0.1"; default = "127.0.0.1";
}; };
@ -39,34 +64,68 @@
}; };
routerAddress = mkOption { routerAddress = mkOption {
type = with types; nullOr str; type = types.str;
default = "http://127.0.0.1:7650"; 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 { routerPassword = mkOption {
type = with types; nullOr str; type = types.str;
default = "itoopie"; default = "itoopie";
}; };
}; };
};
config =
let config = mkIf cfg.enable {
cfg = config.services.i2pd-exporter;
in
lib.mkIf cfg.enable {
systemd.services.i2pd-exporter = { systemd.services.i2pd-exporter = {
description = "Exporter for i2pd";
wantedBy = [ "multi-user.target" ];
environment = { environment = {
IP = cfg.listenAddress; IP = cfg.listenAddress;
PORT = cfg.port; PORT = toString cfg.port;
ADDRESS = cfg.routerAddress;
ROUTER = cfg.routerAddress;
PASSWORD = cfg.routerPassword; PASSWORD = cfg.routerPassword;
}; };
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${pkgs.i2pd-exporter}/bin/i2pdexporter"; 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
];
};
}; };
} }
);
}