From 5b3df769dc30bfb066d537d4f237469fcd06e906 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Mon, 20 Apr 2020 15:00:17 +0200 Subject: [PATCH] chore(nix): provide memcached --- shell.nix | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/shell.nix b/shell.nix index b3d1273a7..59fd7e1dd 100644 --- a/shell.nix +++ b/shell.nix @@ -19,12 +19,22 @@ let ''; override = oldAttrs: { - nativeBuildInputs = oldAttrs.nativeBuildInputs ++ (with pkgs; [ nodejs-13_x postgresql openldap google-chrome exiftool ]) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder ]); + nativeBuildInputs = oldAttrs.nativeBuildInputs ++ (with pkgs; [ nodejs-13_x postgresql openldap google-chrome exiftool memcached ]) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]); shellHook = '' export PROMPT_INFO="${oldAttrs.name}" export EDITOR=emacsclient + cleanup() { + set +e -x + type cleanup_postgres && cleanup_postgres + type cleanup_widget_memcached && cleanup_widget_memcached + type cleanup_session_memcached && cleanup_session_memcached + set +x + } + + trap cleanup EXIT + if [[ -z "$PGHOST" ]]; then set -xe @@ -37,14 +47,42 @@ let psql -f ${postgresSchema} postgres printf "Postgres logfile is %s\nPostgres socket directory is %s\n" ''${pgLogFile} ''${pgSockDir} - cleanup() { + cleanup_postgres() { set +e -x pg_ctl stop -D ''${pgDir} rm -rvf ''${pgDir} ''${pgSockDir} ''${pgLogFile} set +x } - trap cleanup EXIT + set +xe + fi + + if [[ -z "$WIDGET_MEMCACHED_HOST" ]]; then + set -xe + + memcached -l localhost -p 11211 &>/dev/null & + widget_memcached_pid=$? + + cleanup_widget_memcached() { + [[ -n "$widget_memcached_pid" ]] && kill $widget_memcached_pid + } + + export WIDGET_MEMCACHED_HOST=localhost WIDGET_MEMCACHED_PORT=11211 + + set +xe + fi + + if [[ -z "$SESSION_MEMCACHED_HOST" ]]; then + set -xe + + memcached -l localhost -p 11212 &>/dev/null & + session_memcached_pid=$? + + cleanup_session_memcached() { + [[ -n "$session_memcached_pid" ]] && kill $session_memcached_pid + } + + export SESSION_MEMCACHED_HOST=localhost SESSION_MEMCACHED_PORT=11212 set +xe fi