Created
May 10, 2024 16:49
-
-
Save Vaisakhkm2625/8c4852a8cfb99a40d20a0073f8acd258 to your computer and use it in GitHub Desktop.
nix env for Mariadb (default.nix) - thanks - https://github.com/Program-Learning/nix-shell-dev_env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://jeancharles.quillet.org/posts/2022-01-30-Local-mariadb-server-with-nix-shell.html | |
let pkgs = import <nixpkgs> {}; | |
in pkgs.mkShell { | |
buildInputs = [ pkgs.mariadb ]; | |
shellHook = '' | |
MYSQL_BASEDIR=${pkgs.mariadb} | |
MYSQL_HOME=$PWD/mysql | |
MYSQL_DATADIR=$MYSQL_HOME/data | |
export MYSQL_UNIX_PORT=$MYSQL_HOME/mysql.sock | |
MYSQL_PID_FILE=$MYSQL_HOME/mysql.pid | |
alias mysql='mysql -u root' | |
if [ ! -d "$MYSQL_HOME" ]; then | |
# Make sure to use normal authentication method otherwise we can only | |
# connect with unix account. But users do not actually exists in nix. | |
mysql_install_db --auth-root-authentication-method=normal \ | |
--datadir=$MYSQL_DATADIR --basedir=$MYSQL_BASEDIR \ | |
--pid-file=$MYSQL_PID_FILE | |
fi | |
# Starts the daemon | |
mysqld --datadir=$MYSQL_DATADIR --pid-file=$MYSQL_PID_FILE \ | |
--socket=$MYSQL_UNIX_PORT 2> $MYSQL_HOME/mysql.log & | |
MYSQL_PID=$! | |
finish() | |
{ | |
mysqladmin -u root --socket=$MYSQL_UNIX_PORT shutdown | |
kill $MYSQL_PID | |
wait $MYSQL_PID | |
} | |
trap finish EXIT | |
''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment