From 86b48684bb028e551bf6c876d0a0668532ea2f4f Mon Sep 17 00:00:00 2001 From: Ratchanan Srirattanamet Date: Sat, 5 Nov 2022 16:51:30 +0700 Subject: [PATCH] nixos/zoneminder: automatically update Nix store path in config DB ZM has a configuration which defaults to a file in its installaton path. In NixOS, this means a Nix store path is persisted into the database, which will break when e.g. ZM is upgraded. Workaround this by doing a regular expression-based string replacement SQL command to replace this value. The regular expression should not match if users has changed this config to somewhere else. It will match even if ZM isn't upgraded, in which case it'll replace the value with itself. As such, it should be safe to run this at every ZM startup. --- nixos/modules/services/misc/zoneminder.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/modules/services/misc/zoneminder.nix b/nixos/modules/services/misc/zoneminder.nix index 45b554d193d5..11722979851c 100644 --- a/nixos/modules/services/misc/zoneminder.nix +++ b/nixos/modules/services/misc/zoneminder.nix @@ -328,6 +328,14 @@ in { ${zoneminder}/bin/zmupdate.pl -nointeractive ${zoneminder}/bin/zmupdate.pl --nointeractive -f + + # Update ZM's Nix store path in the configuration table. Do nothing if the config doesn't + # contain ZM's Nix store path. + ${config.services.mysql.package}/bin/mysql -u zoneminder zm << EOF + UPDATE Config + SET Value = REGEXP_REPLACE(Value, "^/nix/store/[^-/]+-zoneminder-[^/]+", "${pkgs.zoneminder}") + WHERE Name = "ZM_FONT_FILE_LOCATION"; + EOF ''; serviceConfig = { User = user;