anchor.diff:                        ${concatStringsSep "\n" (mapAttrsToList (database: permission: ''
                           echo "GRANT ${permission} ON ${database} TO '${user.name}'@'localhost';"
                         '') user.ensurePermissions)}
  -                    ) | ${mysql}/bin/mysql -u root -N
  +                    ) | ${cfg.package}/bin/mysql -u root -N
                     '') cfg.ensureUsers}
                 '';
               in
  
positive.code: 
    cfg = config.services.mysql;
  
    mysql = cfg.package;
  
    isMariaDB = lib.getName mysql == lib.getName pkgs.mariadb;
  
    mysqldOptions =
      "--user=${cfg.user} --datadir=${cfg.dataDir} --basedir=${mysql}";
  
    settingsFile = pkgs.writeText "my.cnf" (
      generators.toINI { listsAsDuplicateKeys = true; } cfg.settings +
  
negative.code: 
          preStart = if isMariaDB then ''
            if ! test -e ${cfg.dataDir}/mysql; then
              ${cfg.package}/bin/mysql_install_db --defaults-file=/etc/my.cnf ${mysqldOptions}
              touch ${cfg.dataDir}/mysql_init
            fi
          '' else ''
            if ! test -e ${cfg.dataDir}/mysql; then
              ${cfg.package}/bin/mysqld --defaults-file=/etc/my.cnf ${mysqldOptions} --initialize-insecure
              touch ${cfg.dataDir}/mysql_init
            fi
          '';
  