diff --git a/nix/dev-shell.nix b/nix/dev-shell.nix --- a/nix/dev-shell.nix +++ b/nix/dev-shell.nix @@ -30,6 +30,8 @@ , pkg-config , protobuf_3_15_cmake , python3 +, redis +, redis-up , rustc , shellcheck , sqlite @@ -52,6 +54,7 @@ yarn watchman # react native python3 + redis # native dependencies # C/CXX toolchains are already brought in with mkShell @@ -122,7 +125,10 @@ "${mariadb-up}"/bin/mariadb-up & mariadb_pid=$! - wait "$mariadb_pid" + "${redis-up}"/bin/redis-up & + redis_pid=$! + + wait "$mariadb_pid" "$redis_pid" '' + '' # Provide decent bash prompt diff --git a/nix/overlay.nix b/nix/overlay.nix --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -56,6 +56,8 @@ mysql-up = prev.callPackage ./mysql-up-linux.nix { }; + redis-up = prev.callPackage ./redis-up-mac.nix { }; + olm = prev.olm.overrideAttrs(oldAttrs: { # *.hh files aren't meant to be used externally # so we patch installation to add it diff --git a/nix/redis-up-mac.nix b/nix/redis-up-mac.nix new file mode 100644 --- /dev/null +++ b/nix/redis-up-mac.nix @@ -0,0 +1,44 @@ +{ lib +, redis +, writeShellApplication +, writeTextFile +}: + +let + # Use small script executed by bash to have a normal shell environment. + redis-entrypoint = writeShellApplication { + name = "redis-init"; + text = '' + REDIS_CACHE_DIR=''${XDG_CACHE_HOME:-$HOME/Library/Caches}/Redis + mkdir -p "$REDIS_CACHE_DIR" + # 'exec' allows for us to replace bash process with MariaDB + exec ${redis}/bin/redis-server \ + &> "$REDIS_CACHE_DIR"/logs + ''; + }; + +# will create a shellchecked executable shell script located in $out/bin/ +# This shell script will be used to allow for impure+stateful actions +in writeShellApplication { + name = "redis-up"; + text = '' + # so use XDG conventions and hope $HOME doesn't have a space. + REDIS_CACHE_DIR=''${XDG_CACHE_HOME:-$HOME/Library/Caches}/Redis + REDIS_PIDFILE="$REDIS_CACHE_DIR"/redis.pid + + mkdir -p "$REDIS_CACHE_DIR" + + "${../scripts/start_comm_daemon.sh}" \ + redis \ + Redis \ + ${redis-entrypoint}/bin/redis-init \ + "$REDIS_PIDFILE" + + echo "View Redis Logs: tail -f $REDIS_CACHE_DIR/logs" >&2 + echo "Kill Redis server: pkill redis" >&2 + + # Explicitly exit this script so the parent shell can determine + # when it's safe to return control of terminal to user + exit 0 + ''; +}