As compiling might take long, it is not a good idea to remove the platformio cache with the `rsync --delete` on every deployment.
63 lines
1.6 KiB
Nix
63 lines
1.6 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"
|
|
'';
|
|
};
|
|
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;
|
|
package = pkgs.esphome.overrideAttrs (attrs: {
|
|
makeWrapperArgs = attrs.makeWrapperArgs ++ [
|
|
"--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]}"
|
|
];
|
|
});
|
|
};
|
|
|
|
system.activationScripts.esphome-custom = {
|
|
deps = [ "users" "groups" ];
|
|
text = ''
|
|
${pkgs.rsync}/bin/rsync \
|
|
-a \
|
|
--delete \
|
|
--exclude=.esphome \
|
|
--exclude=.platformio \
|
|
--exclude=.gitignore \
|
|
"${cfgdir}/" "${stateDir}/"
|
|
mkdir -p \
|
|
"${stateDir}/.esphome" \
|
|
"${stateDir}/.platformio"
|
|
touch "${stateDir}/.gitignore"
|
|
chown esphome:esphome \
|
|
"${stateDir}/" \
|
|
"${stateDir}/.esphome" \
|
|
"${stateDir}/.platformio"
|
|
'';
|
|
};
|
|
}
|