From 8eb07d94a12f0fb8d4a8f15043aedc8cadd7c676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 22 Jul 2020 01:16:01 +0200 Subject: Initial commit --- shells/README.md | 3 +++ shells/ipython.nix | 4 ++++ shells/mysql.nix | 26 ++++++++++++++++++++++++++ shells/postgresql.nix | 26 ++++++++++++++++++++++++++ shells/sub_bash.nix | 16 ++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 shells/README.md create mode 100644 shells/ipython.nix create mode 100644 shells/mysql.nix create mode 100644 shells/postgresql.nix create mode 100644 shells/sub_bash.nix (limited to 'shells') diff --git a/shells/README.md b/shells/README.md new file mode 100644 index 0000000..2eeef76 --- /dev/null +++ b/shells/README.md @@ -0,0 +1,3 @@ +This directory regroups regularly-accessed nix-shells that require (or +not) a bit of configuration to run and may not be trivial to write from +scratch. diff --git a/shells/ipython.nix b/shells/ipython.nix new file mode 100644 index 0000000..c04a08f --- /dev/null +++ b/shells/ipython.nix @@ -0,0 +1,4 @@ +with import {}; +mkShell { + buildInputs = [ (python3.withPackages (ps: [ ps.ipython ])) ]; +} diff --git a/shells/mysql.nix b/shells/mysql.nix new file mode 100644 index 0000000..58428ac --- /dev/null +++ b/shells/mysql.nix @@ -0,0 +1,26 @@ +with import {}; + mkShell { + buildInputs = [ mariadb ]; + shellHook = '' + export MARIADBHOST=$PWD/mysql + export LANG=en_US.UTF-8; + export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive; + export MYSQL_UNIX_PORT=$MARIADBHOST/mysql.sock + mkdir -p $MARIADBHOST + cat > $MARIADBHOST/my.cnf < $MARIADBHOST/LOG 2>&1 + mysqld --defaults-file=$MARIADBHOST/my.cnf --datadir=$MARIADBHOST --basedir=${mariadb} --pid-file=$MARIADBHOST/mariadb.pid >> $MARIADBHOST/LOG 2>&1 & + finish() { + mysqladmin shutdown + rm -rf "$MARIADBHOST"; + } + trap finish EXIT + ''; + } + diff --git a/shells/postgresql.nix b/shells/postgresql.nix new file mode 100644 index 0000000..4f7bdc4 --- /dev/null +++ b/shells/postgresql.nix @@ -0,0 +1,26 @@ +with import {}; + mkShell { + buildInputs = [ postgresql_11 glibcLocales ]; + shellHook = '' + export PGDB="dummy"; + export PGDATA=$PWD/postgres + export PGHOST=$PWD/postgres + export PGPORT=5432 + export LOG_PATH=$PWD/postgres/LOG + export PGDATABASE=postgres + export DATABASE_URL="postgresql:///postgres?host=$PGDATA" + export LANG=en_US.UTF-8; + export LOCALE_ARCHIVE=${glibcLocales}/lib/locale/locale-archive; + mkdir -p $PGDATA + echo 'Initializing postgresql database...' + initdb $PGDATA --auth=trust >/dev/null + pg_ctl start -w -l $LOG_PATH -o "-c synchronous_commit=off -c listen_addresses= -c unix_socket_directories=$PGDATA" + createdb "$PGDB"; + finish() { + pg_ctl stop -m fast; + rm -rf "$PGDATA"; + } + trap finish EXIT + ''; + } + diff --git a/shells/sub_bash.nix b/shells/sub_bash.nix new file mode 100644 index 0000000..656b385 --- /dev/null +++ b/shells/sub_bash.nix @@ -0,0 +1,16 @@ +# run with +# nix-shell shell.nix --run 'touch in ; tail -f in | bash & echo $! > pid' +# and then send commands with +# echo 'compute_me "1 + 3"' >> in +{ pkgs ? import {} }: +pkgs.mkShell { + buildInputs = [ pkgs.bc ]; + shellHook = '' + compute_me() { + echo "$1" | bc; + } + export -f compute_me + + echo "I’m ready" + ''; +} -- cgit v1.2.3