mirror of
https://codeberg.org/icewind/wifi-prometheus-exporter.git
synced 2026-06-03 16:44:11 +02:00
flake rework, dep updates
This commit is contained in:
parent
598144ee7d
commit
881c06173b
8 changed files with 738 additions and 521 deletions
954
Cargo.lock
generated
954
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
12
Cargo.toml
12
Cargo.toml
|
|
@ -7,10 +7,10 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ssh2 = "0.9.3"
|
ssh2 = "0.9.4"
|
||||||
dotenv = "0.15.0"
|
dotenvy = "0.15.7"
|
||||||
main_error = "0.1.2"
|
main_error = "0.1.2"
|
||||||
tokio = { version = "1.20.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
|
||||||
warp = "0.3.2"
|
warp = "0.3.6"
|
||||||
ctrlc = "3.2.2"
|
ctrlc = "3.4.2"
|
||||||
rumqttc = "0.12.0"
|
rumqttc = "0.23.0"
|
||||||
|
|
|
||||||
72
flake.lock
generated
72
flake.lock
generated
|
|
@ -1,67 +1,57 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"locked": {
|
|
||||||
"lastModified": 1656928814,
|
|
||||||
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "flake-utils",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"naersk": {
|
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1655042882,
|
"lastModified": 1705309234,
|
||||||
"narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=",
|
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||||
"owner": "nix-community",
|
"owner": "numtide",
|
||||||
"repo": "naersk",
|
"repo": "flake-utils",
|
||||||
"rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f",
|
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nix-community",
|
"owner": "numtide",
|
||||||
"repo": "naersk",
|
"repo": "flake-utils",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 0,
|
"lastModified": 1706956340,
|
||||||
"narHash": "sha256-XZ1fKlEkAQvgocuBYq9lXEP3eNW6gF9JHsPVsvkWMhU=",
|
"narHash": "sha256-g1hZv4OnW2UR6+OBWbeYB2kNnbq0W81wzZhOk/3yoXk=",
|
||||||
"path": "/nix/store/2xbq6yjs2lf2j0438h162mf66jvg0wyg-source",
|
"owner": "NixOS",
|
||||||
"type": "path"
|
"repo": "nixpkgs",
|
||||||
},
|
"rev": "7b9bd55d0f67ee214a8c9f3353ded09618ab51b2",
|
||||||
"original": {
|
"type": "github"
|
||||||
"id": "nixpkgs",
|
|
||||||
"type": "indirect"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 0,
|
|
||||||
"narHash": "sha256-XZ1fKlEkAQvgocuBYq9lXEP3eNW6gF9JHsPVsvkWMhU=",
|
|
||||||
"path": "/nix/store/2xbq6yjs2lf2j0438h162mf66jvg0wyg-source",
|
|
||||||
"type": "path"
|
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
|
"ref": "release-23.11",
|
||||||
"type": "indirect"
|
"type": "indirect"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"naersk": "naersk",
|
"nixpkgs": "nixpkgs"
|
||||||
"nixpkgs": "nixpkgs_2"
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
121
flake.nix
121
flake.nix
|
|
@ -1,126 +1,45 @@
|
||||||
{
|
{
|
||||||
inputs = {
|
inputs = {
|
||||||
|
nixpkgs.url = "nixpkgs/release-23.11";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
naersk.url = "github:nix-community/naersk";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {
|
outputs = {
|
||||||
self,
|
self,
|
||||||
nixpkgs,
|
nixpkgs,
|
||||||
flake-utils,
|
flake-utils,
|
||||||
naersk,
|
|
||||||
}:
|
}:
|
||||||
flake-utils.lib.eachDefaultSystem (
|
flake-utils.lib.eachDefaultSystem (
|
||||||
system: let
|
system: let
|
||||||
pkgs = nixpkgs.legacyPackages."${system}";
|
overlays = [
|
||||||
naersk-lib = naersk.lib."${system}";
|
(import ./overlay.nix)
|
||||||
|
];
|
||||||
|
pkgs = (import nixpkgs) {
|
||||||
|
inherit system overlays;
|
||||||
|
};
|
||||||
in rec {
|
in rec {
|
||||||
# `nix build`
|
packages = rec {
|
||||||
packages.wifi-prometheus-exporter = naersk-lib.buildPackage {
|
inherit (pkgs) wifi-prometheus-exporter;
|
||||||
pname = "wifi-prometheus-exporter";
|
default = wifi-prometheus-exporter;
|
||||||
root = ./.;
|
|
||||||
|
|
||||||
nativeBuildInputs = [pkgs.pkg-config];
|
|
||||||
buildInputs = [pkgs.openssl];
|
|
||||||
};
|
};
|
||||||
defaultPackage = packages.wifi-prometheus-exporter;
|
|
||||||
defaultApp = packages.wifi-prometheus-exporter;
|
|
||||||
|
|
||||||
# `nix develop`
|
devShells.default = pkgs.mkShell {
|
||||||
devShell = pkgs.mkShell {
|
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated openssl pkg-config clippy];
|
||||||
nativeBuildInputs = with pkgs; [rustc cargo bacon cargo-edit cargo-outdated pkgs.openssl pkgs.pkg-config];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
// {
|
// {
|
||||||
nixosModule = {
|
overlays.default = import ./overlay.nix;
|
||||||
|
nixosModules.default = {
|
||||||
|
pkgs,
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}: {
|
||||||
with lib; let
|
imports = [./module.nix];
|
||||||
cfg = config.services.wifi-prometheus-exporter;
|
config = lib.mkIf config.services.wifi-prometheus-exporter.enable {
|
||||||
in {
|
nixpkgs.overlays = [self.overlays.default];
|
||||||
options.services.wifi-prometheus-exporter = {
|
services.wifi-prometheus-exporter.package = lib.mkDefault pkgs.wifi-prometheus-exporter;
|
||||||
enable = mkEnableOption "WiFi prometheus exporter";
|
|
||||||
|
|
||||||
sshAddress = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "ssh address of the wifi access point";
|
|
||||||
};
|
|
||||||
|
|
||||||
sshKeyFile = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "path containing the ssh private key";
|
|
||||||
};
|
|
||||||
|
|
||||||
sshPubKeyFile = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "path containing the ssh public key";
|
|
||||||
};
|
|
||||||
|
|
||||||
interfaces = mkOption {
|
|
||||||
type = types.listOf types.str;
|
|
||||||
description = "access point interface to expose";
|
|
||||||
};
|
|
||||||
|
|
||||||
port = mkOption {
|
|
||||||
type = types.int;
|
|
||||||
default = 9010;
|
|
||||||
description = "port to listen to";
|
|
||||||
};
|
|
||||||
|
|
||||||
mqttSecretFile = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
description = "path containing MQTT_HOSTNAME, MQTT_USERNAME and MQTT_PASSWORD environment variables";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
|
||||||
systemd.services."wifi-prometheus-exporter" = let
|
|
||||||
pkg = self.defaultPackage.${pkgs.system};
|
|
||||||
in {
|
|
||||||
wantedBy = ["multi-user.target"];
|
|
||||||
script = "${pkg}/bin/wifi-prometheus-exporter";
|
|
||||||
environment = {
|
|
||||||
PORT = toString cfg.port;
|
|
||||||
ADDR = cfg.sshAddress;
|
|
||||||
KEYFILE = cfg.sshKeyFile;
|
|
||||||
PUBFILE = cfg.sshPubKeyFile;
|
|
||||||
INTERFACES = concatStringsSep " " cfg.interfaces;
|
|
||||||
};
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
EnvironmentFile = cfg.mqttSecretFile;
|
|
||||||
Restart = "on-failure";
|
|
||||||
DynamicUser = true;
|
|
||||||
PrivateTmp = true;
|
|
||||||
ProtectSystem = "strict";
|
|
||||||
ProtectHome = true;
|
|
||||||
NoNewPrivileges = true;
|
|
||||||
PrivateDevices = true;
|
|
||||||
ProtectClock = true;
|
|
||||||
CapabilityBoundingSet = true;
|
|
||||||
ProtectKernelLogs = true;
|
|
||||||
ProtectControlGroups = true;
|
|
||||||
SystemCallArchitectures = "native";
|
|
||||||
ProtectKernelModules = true;
|
|
||||||
RestrictNamespaces = true;
|
|
||||||
MemoryDenyWriteExecute = true;
|
|
||||||
ProtectHostname = true;
|
|
||||||
LockPersonality = true;
|
|
||||||
ProtectKernelTunables = true;
|
|
||||||
RestrictAddressFamilies = "AF_INET AF_INET6";
|
|
||||||
RestrictRealtime = true;
|
|
||||||
ProtectProc = "noaccess";
|
|
||||||
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
|
||||||
IPAddressDeny = "any";
|
|
||||||
IPAddressAllow = ["192.168.0.0/16" "localhost"];
|
|
||||||
PrivateUsers = true;
|
|
||||||
ProcSubset = "pid";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
94
module.nix
Normal file
94
module.nix
Normal file
|
|
@ -0,0 +1,94 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
with lib; let
|
||||||
|
cfg = config.services.wifi-prometheus-exporter;
|
||||||
|
in {
|
||||||
|
options.services.wifi-prometheus-exporter = {
|
||||||
|
enable = mkEnableOption "WiFi prometheus exporter";
|
||||||
|
|
||||||
|
sshAddress = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "ssh address of the wifi access point";
|
||||||
|
};
|
||||||
|
|
||||||
|
sshKeyFile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "path containing the ssh private key";
|
||||||
|
};
|
||||||
|
|
||||||
|
sshPubKeyFile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "path containing the ssh public key";
|
||||||
|
};
|
||||||
|
|
||||||
|
interfaces = mkOption {
|
||||||
|
type = types.listOf types.str;
|
||||||
|
description = "access point interface to expose";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 9010;
|
||||||
|
description = "port to listen to";
|
||||||
|
};
|
||||||
|
|
||||||
|
mqttSecretFile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
description = "path containing MQTT_HOSTNAME, MQTT_USERNAME and MQTT_PASSWORD environment variables";
|
||||||
|
};
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
defaultText = literalExpression "pkgs.dispenser";
|
||||||
|
description = "package to use";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
systemd.services."wifi-prometheus-exporter" = {
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
environment = {
|
||||||
|
PORT = toString cfg.port;
|
||||||
|
ADDR = cfg.sshAddress;
|
||||||
|
KEYFILE = cfg.sshKeyFile;
|
||||||
|
PUBFILE = cfg.sshPubKeyFile;
|
||||||
|
INTERFACES = concatStringsSep " " cfg.interfaces;
|
||||||
|
};
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.wifi-prometheus-exporter}/bin/wifi-prometheus-exporter";
|
||||||
|
EnvironmentFile = cfg.mqttSecretFile;
|
||||||
|
Restart = "on-failure";
|
||||||
|
DynamicUser = true;
|
||||||
|
PrivateTmp = true;
|
||||||
|
ProtectSystem = "strict";
|
||||||
|
ProtectHome = true;
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
PrivateDevices = true;
|
||||||
|
ProtectClock = true;
|
||||||
|
CapabilityBoundingSet = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
SystemCallArchitectures = "native";
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
MemoryDenyWriteExecute = true;
|
||||||
|
ProtectHostname = true;
|
||||||
|
LockPersonality = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
RestrictAddressFamilies = "AF_INET AF_INET6";
|
||||||
|
RestrictRealtime = true;
|
||||||
|
ProtectProc = "noaccess";
|
||||||
|
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
||||||
|
IPAddressDeny = "any";
|
||||||
|
IPAddressAllow = ["192.168.0.0/16" "localhost"];
|
||||||
|
PrivateUsers = true;
|
||||||
|
ProcSubset = "pid";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
3
overlay.nix
Normal file
3
overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
final: prev: {
|
||||||
|
wifi-prometheus-exporter = final.callPackage ./package.nix {};
|
||||||
|
}
|
||||||
29
package.nix
Normal file
29
package.nix
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
rustPlatform,
|
||||||
|
openssl,
|
||||||
|
pkg-config,
|
||||||
|
lib,
|
||||||
|
}: let
|
||||||
|
inherit (lib.sources) sourceByRegex;
|
||||||
|
src = sourceByRegex ./. ["Cargo.*" "(src)(/.*)?"];
|
||||||
|
in
|
||||||
|
rustPlatform.buildRustPackage rec {
|
||||||
|
pname = "wifi-prometheus-exporter";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
inherit src;
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
openssl
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
doCheck = false;
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -66,7 +66,7 @@ impl WifiLister {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), MainError> {
|
async fn main() -> Result<(), MainError> {
|
||||||
let mut env: HashMap<String, String> = dotenv::vars().collect();
|
let mut env: HashMap<String, String> = dotenvy::vars().collect();
|
||||||
let addr = env.remove("ADDR").ok_or("No ADDR set")?;
|
let addr = env.remove("ADDR").ok_or("No ADDR set")?;
|
||||||
let keyfile = env.remove("KEYFILE").ok_or("No KEYFILE set")?;
|
let keyfile = env.remove("KEYFILE").ok_or("No KEYFILE set")?;
|
||||||
let pubfile = env.remove("PUBFILE").ok_or("No PUBFILE set")?;
|
let pubfile = env.remove("PUBFILE").ok_or("No PUBFILE set")?;
|
||||||
|
|
@ -226,7 +226,7 @@ async fn send_update(
|
||||||
mac: String,
|
mac: String,
|
||||||
update: Update,
|
update: Update,
|
||||||
) -> Result<(), ClientError> {
|
) -> Result<(), ClientError> {
|
||||||
let mac = mac.replace(":", "_");
|
let mac = mac.replace(':', "_");
|
||||||
match update {
|
match update {
|
||||||
Update::New => {
|
Update::New => {
|
||||||
client
|
client
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue