devenv/mysql.nix

30 lines
607 B
Nix
Raw Normal View History

2020-05-26 19:42:16 +02:00
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
2020-12-17 15:57:59 +01:00
sql_file = "data/db.sql";
data_dir = "$(pwd)/.mysql";
socket = "${data_dir}/mysql.sock";
in mkShell {
2020-11-30 20:45:42 +01:00
buildInputs = [ mysql80 ];
2020-05-26 19:42:16 +02:00
shellHook = ''
trap "kill 0" EXIT
2020-05-26 19:42:16 +02:00
if [ ! -d ${data_dir} ]; then
mysqld --datadir="${data_dir}" --socket="${socket}" --initialize-insecure
fi
2020-11-30 20:45:42 +01:00
mysqld --datadir="${data_dir}" --socket="${socket}" --skip-networking --skip-mysqlx &
2020-05-26 19:42:16 +02:00
sleep 1
mysql --socket="${socket}" -u root < ${sql_file}
2020-05-26 19:42:16 +02:00
alias mysql='mysql --socket="${socket}" -u root'
alias nuke='rm -rf ${data_dir}'
2020-05-26 19:42:16 +02:00
'';
}