stockholm/krebs/2configs/shack/node-light.nix

62 lines
1.7 KiB
Nix
Raw Permalink Normal View History

2019-07-11 16:11:50 +00:00
{ config, lib, pkgs, ... }:
let
pkg = pkgs.callPackage (
2021-09-05 17:51:31 +00:00
pkgs.fetchFromGitHub {
owner = "shackspace";
repo = "node-light";
rev = "90a9347b73af3a9960bd992e6293b357226ef6a0";
sha256 = "1av9w3w8aknlra25jw6gqxzbb01i9kdlfziy29lwz7mnryjayvwk";
}) { };
2019-07-11 16:11:50 +00:00
home = "/var/lib/node-light";
port = "8082";
in {
# receive response from light.shack / standby.shack
networking.firewall.allowedUDPPorts = [ 2342 ];
users.users.node-light = {
inherit home;
2021-06-05 17:13:25 +00:00
isSystemUser = true;
2019-07-11 16:11:50 +00:00
createHome = true;
group = "node-light";
2019-07-11 16:11:50 +00:00
};
users.groups.node-light = {};
2019-07-11 16:11:50 +00:00
services.nginx.virtualHosts."lounge.light.shack" = {
locations."/" = {
proxyPass = "http://localhost:${port}/lounge/";
};
};
services.nginx.virtualHosts."power.light.shack" = {
locations."/" = {
proxyPass = "http://localhost:${port}/power/";
};
};
services.nginx.virtualHosts."openhab.shack" = {
2020-09-13 11:56:58 +00:00
extraConfig = ''
access_log syslog:server=unix:/dev/log combined if=$loggable;
'';
2019-07-11 16:11:50 +00:00
serverAliases = [ "lightapi.shack" ];
2019-07-16 16:57:09 +00:00
locations."/power/".proxyPass = "http://localhost:${port}/power/";
locations."/lounge/".proxyPass = "http://localhost:${port}/lounge/";
2019-07-11 16:11:50 +00:00
};
systemd.services.node-light= {
description = "node-light";
wantedBy = [ "multi-user.target" ];
environment.PORT = port;
serviceConfig = {
User = "node-light";
# do not override the current storage file
ExecStartPre = pkgs.writeDash "call-light-pre" ''
cp -vn ${pkg}/share/storage.json ${home}
chmod 700 ${home}/storage.json
'';
WorkingDirectory = home;
ExecStart = "${pkg}/bin/node-light";
PrivateTmp = true;
2019-09-26 19:46:14 +00:00
Restart = "always";
RestartSec = "15";
2019-07-11 16:11:50 +00:00
};
};
}