nixos/frigate: retain the runtime state file

Some of the runtime knobs cannot be replicated well with file-based
configuration. A prime example of this is soft-disabling a camera (I
have my 3D printer camera in frigate, why are you looking at me like
that 😅)

In short, `camera.enabled: false` in config will hard-disable the camera
instead and it cannot be re-enabled either via UI or MQTT. The UI/MQTT
toggle, however does remember the camera state across restarts and will
restore it when it starts back up, making it a soft-disable mechanism.

This state is stored in the file next to the config without a way to
move it. We also can't use a Bind mount or symlink for this file,
because frigate utilizes the atomic-move pattern to atomically modify
this file, which doesn't work with bind mounts and will overwrite the
symlink.
This commit is contained in:
Simonas Kazlauskas
2026-10-19 01:36:36 +03:00
parent 2ab4354ea4
commit 39b2cccebd

View File

@@ -733,7 +733,10 @@ in
"multi-user.target"
];
environment = {
CONFIG_FILE = "/run/frigate/frigate.yml";
# Frigate keeps some of its persistent runtime state in a file next to the configuration,
# so the config must also live in persistent storage (even though we overwrite it on every
# startup.)
CONFIG_FILE = "/var/lib/frigate/frigate.yml";
HOME = "/var/lib/frigate";
PYTHONPATH = cfg.package.pythonPath;
}
@@ -762,7 +765,7 @@ in
${lib.getExe pkgs.findutils} /var/cache/frigate -not -path '/var/cache/frigate/model_cache/*' -type f -delete
'')
(pkgs.writeShellScript "frigate-create-writable-config" ''
cp --no-preserve=mode ${configFile} /run/frigate/frigate.yml
cp --no-preserve=mode ${configFile} "$CONFIG_FILE"
'')
]
++ lib.optionals (!config.systemd.services.frigate.environment ? LIBAVFORMAT_VERSION_MAJOR) [