devenv/env/mysql.nix

26 lines
570 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
[ -d ${data_dir} ] || mkdir ${data_dir}
mysqld --datadir="${data_dir}" --socket="${socket}" --initialize-insecure
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'
'';
}