devenv/env/mysql.nix

26 lines
570 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
[ -d ${data_dir} ] || mkdir ${data_dir}
2020-05-26 19:42:16 +02:00
mysqld --datadir="${data_dir}" --socket="${socket}" --initialize-insecure
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'
2020-05-26 19:42:16 +02:00
'';
}