From 367a7f80993306f42ae18d07a56b510fc1402b98 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 18 Jan 2025 13:08:27 +0200 Subject: feat: Add nix setup for apache hosting --- shell.nix | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'shell.nix') diff --git a/shell.nix b/shell.nix index 0f0b24a..a2ad4ac 100644 --- a/shell.nix +++ b/shell.nix @@ -4,18 +4,57 @@ let shellDrv = { mkShell, + gettext, mariadb, apacheHttpd, ... }: mkShell { nativeBuildInputs = [ + gettext mariadb apacheHttpd ]; # Thanks https://github.com/JianZcar/LAMP-nix-shell-env/blob/main/default.nix shellHook = '' + # + # Apache2 + # + + : ''${SERVER_ROOT:=${apacheHttpd}} + : ''${SERVER_PORT:=8000} + : ''${ROOT_DIR:=$HOME/.config/apache} + : ''${REPOSITORY:=${builtins.getEnv "PWD"}} + export SERVER_ROOT SERVER_PORT ROOT_DIR REPOSITORY + + if [ ! -d "$ROOT_DIR" ] + then + echo 'Installing apache config...' + mkdir -p "$ROOT_DIR" + for file in $(find ./apache -type f) + do + file="''${file#./apache/}" + + dir="''${file%/*}" + [ "$dir" != "$file" ] && mkdir -p "$ROOT_DIR/$dir" + + if [ "$file" != "''${file%.tpl}" ] + then + envsubst < "./apache/$file" > "$ROOT_DIR/''${file%.tpl}" + else + cp "./apache/$file" "$ROOT_DIR/$file" + fi + done + fi + + echo 'Starting httpd...' + httpd -f $ROOT_DIR/httpd.conf + + # + # Database + # + : ''${MYSQL_HOME:="$HOME/.config/mysql"} : ''${MYSQL_DATADIR:="$MYSQL_HOME/data"} : ''${MYSQL_PID_FILE:="$MYSQL_HOME/mysql.pid"} @@ -74,6 +113,9 @@ let # Start user's shell "$(getent passwd $USER | cut -d : -f 7)" + echo 'Shutting down httpd...' + httpd -f $ROOT_DIR/httpd.conf -k stop + # Stop mysql echo 'Shutting down mysql...' mysqladmin \ -- cgit v1.2.3