50 lines
1.3 KiB
Nix
50 lines
1.3 KiB
Nix
args@{ lib, pkgs, config, custom-utils, ... }:
|
|
let
|
|
ports = import ../../ports.nix args;
|
|
cfg = config.services.esphome;
|
|
stateDir = "/var/lib/esphome";
|
|
devices = [
|
|
./yeelight-meteorite.yaml
|
|
];
|
|
cfgdir = pkgs.stdenvNoCC.mkDerivation {
|
|
name = "esphome-config";
|
|
src = ./devices;
|
|
dontBuild = true;
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp -r * $out
|
|
ln -snf "${config.sops.secrets.esphome.path}" "$out/secrets.yaml"
|
|
ln -snf "${stateDir}/.esphome" "$out/.esphome"
|
|
ln -snf "${stateDir}/.gitignore" "$out/.gitignore"
|
|
'';
|
|
};
|
|
esphomeParams =
|
|
if cfg.enableUnixSocket
|
|
then "--socket /run/esphome/esphome.sock"
|
|
else "--address ${cfg.address} --port ${toString cfg.port}";
|
|
in
|
|
{
|
|
sops.secrets.esphome = {
|
|
sopsFile = ../../secrets.yaml;
|
|
owner = "esphome";
|
|
group = "esphome";
|
|
mode = "0400";
|
|
};
|
|
|
|
services.esphome = {
|
|
enable = true;
|
|
address = "127.0.0.1";
|
|
port = ports.esphome.tcp;
|
|
};
|
|
|
|
systemd.services.esphome.serviceConfig = {
|
|
WorkingDirectory = lib.mkForce cfgdir;
|
|
ExecStart = lib.mkForce "${cfg.package}/bin/esphome dashboard ${esphomeParams} ${cfgdir}";
|
|
};
|
|
|
|
system.activationScripts.esphome-custom.text = ''
|
|
mkdir -p "${stateDir}/.esphome"
|
|
touch "${stateDir}/.gitignore"
|
|
chown esphome:esphome "${stateDir}/.esphome" "${stateDir}/.gitignore"
|
|
'';
|
|
}
|