mirror of
https://codeberg.org/icewind/mitemp-prometheus.git
synced 2026-06-03 09:04:13 +02:00
add module
This commit is contained in:
parent
7c3d4a7867
commit
9d40881429
5 changed files with 154 additions and 2 deletions
12
dbus-bluetooth.xml
Normal file
12
dbus-bluetooth.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig>
|
||||
<policy user="mitemp">
|
||||
<allow own="org.bluez"/>
|
||||
<allow send_destination="org.bluez"/>
|
||||
<allow send_interface="org.bluez.GattCharacteristic1"/>
|
||||
<allow send_interface="org.bluez.GattDescriptor1"/>
|
||||
<allow send_interface="org.freedesktop.DBus.ObjectManager"/>
|
||||
<allow send_interface="org.freedesktop.DBus.Properties"/>
|
||||
</policy>
|
||||
</busconfig>
|
||||
19
flake.nix
19
flake.nix
|
|
@ -10,5 +10,22 @@
|
|||
inputs.flakelight.follows = "flakelight";
|
||||
};
|
||||
};
|
||||
outputs = { mill-scale, ... }: mill-scale ./. { };
|
||||
outputs = { mill-scale, ... }: mill-scale ./. {
|
||||
packages.mitemp-prometheus = import ./package.nix;
|
||||
|
||||
nixosModules = { outputs, ... }: {
|
||||
default =
|
||||
{ pkgs
|
||||
, config
|
||||
, lib
|
||||
, ...
|
||||
}: {
|
||||
imports = [ ./module.nix ];
|
||||
config = lib.mkIf config.services.mitemp.enable {
|
||||
nixpkgs.overlays = [ outputs.overlays.default ];
|
||||
services.mitemp.package = lib.mkDefault pkgs.mitemp-prometheus;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
82
module.nix
Normal file
82
module.nix
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
{ config
|
||||
, lib
|
||||
, pkgs
|
||||
, ...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.mitemp;
|
||||
format = pkgs.formats.toml { };
|
||||
configFile = format.generate "mitemp-config.toml" {
|
||||
inherit (cfg) names;
|
||||
listen = {
|
||||
inherit (cfg) socket;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.mitemp = {
|
||||
enable = mkEnableOption "mitemp";
|
||||
|
||||
names = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
description = "Names for mitemp sensors";
|
||||
};
|
||||
|
||||
socket = mkOption {
|
||||
type = types.str;
|
||||
default = "/run/mitemp/mitemp.sock";
|
||||
description = "socket to listen on";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
defaultText = literalExpression "pkgs.mitemp-prometheus";
|
||||
description = "package to use";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
users.users.mitemp = {
|
||||
isSystemUser = true;
|
||||
group = "mitemp";
|
||||
};
|
||||
users.groups.mitemp = {};
|
||||
|
||||
services.dbus.packages = [cfg.package];
|
||||
systemd.services."mitemp" = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "dbus.service" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${cfg.package}/bin/mitemp-prometheus ${configFile}";
|
||||
|
||||
Restart = "on-failure";
|
||||
User = "mitemp";
|
||||
PrivateTmp = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
NoNewPrivileges = 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_UNIX" ];
|
||||
RuntimeDirectory = "mitemp";
|
||||
RestrictRealtime = true;
|
||||
ProtectProc = "noaccess";
|
||||
SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
|
||||
IPAddressDeny = "any";
|
||||
PrivateUsers = true;
|
||||
ProcSubset = "pid";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
38
package.nix
Normal file
38
package.nix
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
{ stdenv
|
||||
, rustPlatform
|
||||
, lib
|
||||
, pkg-config
|
||||
, dbus
|
||||
}:
|
||||
let
|
||||
inherit (lib.sources) sourceByRegex;
|
||||
inherit (builtins) fromTOML readFile;
|
||||
src = sourceByRegex ./. [ "Cargo.*" "(src)(/.*)?" ];
|
||||
cargoToml = (fromTOML (readFile ./Cargo.toml)).package;
|
||||
in
|
||||
rustPlatform.buildRustPackage rec {
|
||||
pname = cargoToml.name;
|
||||
|
||||
inherit src;
|
||||
inherit (cargoToml) version;
|
||||
|
||||
buildInputs = [
|
||||
dbus
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkg-config
|
||||
];
|
||||
|
||||
preInstall = ''
|
||||
mkdir -p $out/share/dbus-1/system.d
|
||||
cp ${./dbus-bluetooth.xml} $out/share/dbus-1/system.d/dbus-bluetooth.conf
|
||||
'';
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ./Cargo.lock;
|
||||
outputHashes = {
|
||||
"btleplug-0.11.6" = "sha256-Y9QZ6er/zaXALiQUUw8mMvzg15Dhz9NsWQ2WAM/ouh0=";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ use main_error::MainError;
|
|||
use mitemp::{listen, BDAddr, Sensor};
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fmt::Write;
|
||||
use std::fs::set_permissions;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::{pin, spawn};
|
||||
use tokio_stream::StreamExt;
|
||||
|
|
@ -76,7 +78,8 @@ async fn main() -> Result<(), MainError> {
|
|||
warp::serve(metrics).run((address, port)).await;
|
||||
}
|
||||
ListenConfig::Unix { socket: path } => {
|
||||
let listener = UnixListener::bind(path).unwrap();
|
||||
let listener = UnixListener::bind(&path)?;
|
||||
set_permissions(&path, PermissionsExt::from_mode(0o666))?;
|
||||
let incoming = UnixListenerStream::new(listener);
|
||||
warp::serve(metrics).run_incoming(incoming).await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue