devenv/mysql.nix

29 lines
571 B
Nix

{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
sql_file = "data/db.sql";
data_dir = "$(pwd)/.mysql";
socket = "${data_dir}/mysql.sock";
in mkShell {
buildInputs = [ mysql80 ];
shellHook = ''
trap "kill 0" EXIT
if [ ! -d ${data_dir} ]; then
mysqld --datadir="${data_dir}" --socket="${socket}" --initialize-insecure
fi
mysqld --datadir="${data_dir}" --socket="${socket}" --skip-networking --skip-mysqlx &
sleep 1
mysql --socket="${socket}" -u root < ${sql_file}
alias mysql='mysql --socket="${socket}" -u root'
'';
}