anchor.diff:            procps
             psmisc
           ];
  -        after = [ "mysql.service" "nginx.service" ];
  +        after = [ "nginx.service" ] ++ lib.optional cfg.database.createLocally "mysql.service";
           wantedBy = [ "multi-user.target" ];
           restartTriggers = [ defaultsFile configFile ];
  -        preStart = lib.mkIf useCustomDir ''
  +        preStart = lib.optionalString useCustomDir ''
             install -dm775 -o ${user} -g ${group} ${cfg.storageDir}/{${lib.concatStringsSep "," libDirs}}
  +        '' + lib.optionalString cfg.database.createLocally ''
  +          if ! test -e "/var/lib/${dirName}/db-created"; then
  +            ${config.services.mysql.package}/bin/mysql < ${pkg}/share/zoneminder/db/zm_create.sql
  +            touch "/var/lib/${dirName}/db-created"
  +          fi
           '';
           serviceConfig = {
             User = user;
  
positive.code:   };
  
    config = lib.mkIf cfg.enable {
  
      environment.etc = {
        "zoneminder/60-defaults.conf".source = defaultsFile;
  
negative.code:       };
  
        mysql = lib.mkIf cfg.database.createLocally {
          enable = true;
          package = lib.mkDefault pkgs.mariadb;
          ensureDatabases = [ cfg.database.name ];
          ensureUsers = [{
            name = cfg.database.username;
            ensurePermissions = { "${cfg.database.name}.*" = "ALL PRIVILEGES"; };
  