40 lines
1018 B
Nix
40 lines
1018 B
Nix
|
{ pkgs ? import <nixpkgs> { } }:
|
||
|
|
||
|
with pkgs;
|
||
|
|
||
|
let
|
||
|
mysql_file = "mysql.sql";
|
||
|
psql_file = "psql.sql";
|
||
|
mysql_dir = "$(pwd)/.mysql";
|
||
|
psql_dir = "$(pwd)/.pgdata";
|
||
|
socket = "${mysql_dir}/mysql.sock";
|
||
|
|
||
|
in mkShell {
|
||
|
buildInputs = [ mysql57 postgresql pgloader ];
|
||
|
|
||
|
shellHook = ''
|
||
|
trap "kill 0" EXIT
|
||
|
export PGDATA="${psql_dir}"
|
||
|
export PGHOST="${psql_dir}"
|
||
|
|
||
|
# MySQL initialization
|
||
|
if [ ! -d ${mysql_dir} ]; then
|
||
|
mysqld --datadir="${mysql_dir}" --socket="${socket}" --initialize-insecure
|
||
|
fi
|
||
|
mysqld --datadir="${mysql_dir}" --socket="${socket}" --skip-networking &
|
||
|
sleep 1
|
||
|
|
||
|
# PostgreSQL initialization
|
||
|
if [ ! -d ${psql_dir} ]; then
|
||
|
initdb --auth-local=trust --no-locale --encoding=UTF8
|
||
|
fi
|
||
|
pg_ctl start -o "--unix_socket_directories=${psql_dir} --listen_addresses='''"
|
||
|
|
||
|
mysql --socket="${socket}" -u root < ${mysql_file}
|
||
|
psql -d postgres -f ${psql_file}
|
||
|
|
||
|
alias mysql='mysql --socket="${socket}" -u root'
|
||
|
alias psql='psql -d postgres'
|
||
|
'';
|
||
|
}
|