How to set datadir to different values based on the hostname in my.cnf?
A simple solution for that would be to keep the my.cnf file identical, and use symlinks on your machine sto point to whatever directory you want the data to be in. For example, assuming you my.cnf contains this:

[mysqld]
datadir=/mysql_data


On you linux host, you would:

cd /
ln -s /var/lib/mysql mysql_data


Add permissions to this folder for mysql user:

chown mysql:mysql /mysql_data