Use rsync to manage esphome config directory

esphome tries to write build outputs to /nix/store which of course does
not work as it is read-only.
This commit is contained in:
Jakob Lechner 2024-02-19 15:33:09 +00:00
parent 9bd6400f39
commit 761831fdbe

View file

@ -14,8 +14,6 @@ let
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 =
@ -35,39 +33,19 @@ in
enable = true;
address = "127.0.0.1";
port = ports.esphome.tcp;
/*
package = pkgs.esphome.overrideAttrs (o: o // {
propagatedBuildInputs = (o.propagatedBuildInputs or []) ++ [
pkgs.gcc
package = pkgs.esphome.overrideAttrs (attrs: {
makeWrapperArgs = attrs.makeWrapperArgs ++ [
"--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]}"
];
makeWrapperArgs = [
# platformio is used in esphomeyaml/platformio_api.py
# esptool is used in esphomeyaml/__main__.py
# git is used in esphomeyaml/writer.py
"--prefix PATH : ${lib.makeBinPath (with pkgs; [ platformio esptool_3 git gcc])}"
"--set ESPHOME_USE_SUBPROCESS ''"
];
});
*/
};
systemd.services.esphome.serviceConfig = {
WorkingDirectory = lib.mkForce cfgdir;
ExecStart = lib.mkForce "${cfg.package}/bin/esphome dashboard ${esphomeParams} ${cfgdir}";
/*
Environment = [
"NIX_LD=/nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/ld-linux-x86-64.so.2"
"NIX_LD_LIBRARY_PATH=/nix/store/myw67gkgayf3s2mniij7zwd79lxy8v0k-gcc-12.3.0-lib/lib"
];
*/
});
};
system.activationScripts.esphome-custom = {
deps = [ "users" "groups" ];
text = ''
mkdir -p "${stateDir}/.esphome"
touch "${stateDir}/.gitignore"
chown esphome:esphome "${stateDir}/.esphome" "${stateDir}/.gitignore"
${pkgs.rsync}/bin/rsync -a --delete "${cfgdir}/" "${stateDir}/"
chown esphome:esphome "${stateDir}/"
'';
};
}