mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
hosts/shinmyoumaru: DHT22 exporting functional
This commit is contained in:
parent
3b09618c50
commit
5fa27d3eb2
3 changed files with 63 additions and 0 deletions
|
|
@ -6,6 +6,8 @@
|
|||
imports = with meta; [
|
||||
profiles.hardware.raspi
|
||||
profiles.base
|
||||
services.dnscrypt-proxy
|
||||
services.dht22-exporter
|
||||
./image.nix
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,16 @@
|
|||
};
|
||||
};
|
||||
|
||||
services.udev.extraRules = ''
|
||||
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
|
||||
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="${pkgs.runtimeShell} -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
|
||||
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="${pkgs.runtimeShell} -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
|
||||
|
||||
T
|
||||
'';
|
||||
|
||||
users.groups.gpio = {};
|
||||
|
||||
environment.noXlibs = true;
|
||||
documentation.info.enable = false;
|
||||
documentation.man.enable = false;
|
||||
|
|
|
|||
51
config/services/dht22-exporter/default.nix
Normal file
51
config/services/dht22-exporter/default.nix
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{ config, lib, pkgs, ... }: with lib; let
|
||||
cfg = config.services.dht22-exporter;
|
||||
in {
|
||||
options.services.dht22-exporter.socat = {
|
||||
enable = mkEnableOption "socat service";
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.socat;
|
||||
};
|
||||
addresses = mkOption {
|
||||
type = with types; coercedTo str singleton (listOf str);
|
||||
default = singleton "::1";
|
||||
};
|
||||
};
|
||||
config = {
|
||||
systemd.services = mkIf cfg.socat.enable {
|
||||
dht22-exporter-socat = let
|
||||
scfg = cfg.socat;
|
||||
service = singleton "dht22-exporter.service";
|
||||
in {
|
||||
after = service;
|
||||
bindsTo = service;
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
};
|
||||
script = let
|
||||
port = toString (if cfg.port == null then 8001 else cfg.port);
|
||||
addresser = addr: "${scfg.package}/bin/socat TCP6-LISTEN:${port},bind=${addr},fork TCP4:localhost:${port}";
|
||||
lines = map addresser scfg.addresses;
|
||||
in ''
|
||||
${concatStringsSep "\n" lines}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
users.users.dht22-exporter = {
|
||||
isSystemUser = true;
|
||||
};
|
||||
|
||||
services.dht22-exporter = {
|
||||
enable = true;
|
||||
platform = "pi";
|
||||
address = "127.0.0.1";
|
||||
socat = {
|
||||
enable = true;
|
||||
};
|
||||
user = "dht22-exporter";
|
||||
group = "gpio";
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue