devenv/env/mysql.nix

26 lines
560 B
Nix
Raw Normal View History

2020-05-26 19:42:16 +02:00
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
sql_file = "database/db.sql";
data_dir = "$(pwd)/.mysql";
socket = "${data_dir}/mysql.sock";
in mkShell {
2020-05-26 19:42:16 +02:00
buildInputs = [ mysql57 ];
shellHook = ''
trap "kill 0" EXIT
[ -d ${data_dir} ] || mkdir ${data_dir}
2020-05-26 19:42:16 +02:00
mysqld --datadir="${data_dir}" --socket="${socket}" --initialize-insecure
mysqld --datadir="${data_dir}" --socket="${socket}" --skip-networking &
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'
2020-05-26 19:42:16 +02:00
'';
}