Commit 86b48684 authored by Ratchanan Srirattanamet's avatar Ratchanan Srirattanamet
Browse files

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.
parent 8093c136
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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;