erpnext-nix/scripts/run-erpnext.nix

59 lines
1.5 KiB
Nix

{ mariadb-client
, python3
, nodejs
, writeShellApplication
, erpnext-apps-sites
, erpnext-nginx-conf
}:
let
penv = python3.buildEnv.override {
extraLibs = [
python3.pkgs.frappe
python3.pkgs.erpnext
python3.pkgs.bench
];
};
in writeShellApplication {
name = "run-erpnext";
runtimeInputs = [mariadb-client nodejs penv];
text = ''
export PYTHON_PATH=${penv}/${python3.sitePackages}
tmp=/tmp/erpnext
mkdir -p $tmp/sites $tmp/config/pids $tmp/logs/nginx $tmp/env/bin
ln -s ${erpnext-apps-sites}/share/apps $tmp/apps
for f in ${erpnext-apps-sites}/share/sites/*; do
ln -s "$f" "$tmp/sites/$(basename "$f")"
done
cat >$tmp/sites/common_site_config.json <<EOF
{
"db_host": "localhost",
"db_port": 3306,
"db_name": "erpnext" ,
"db_password": "erpnext" ,
"redis_cache": "redis://localhost:6379?db=0",
"redis_queue": "redis://localhost:6379?db=1",
"redis_socketio": "redis://localhost:6379?db=2",
"socketio_port": 3000
}
EOF
ln -s ${penv} $tmp/env
ln -sf ${erpnext-nginx-conf} $tmp/nginx-erpnext.conf
cd $tmp
# Upstream initializes the DB with this command
bench new-site localhost --mariadb-root-password password --admin-password admin
bench --site localhost install-app erpnext
echo "Workdir: $tmp"
node $tmp/apps/frappe/socketio.js &
gunicorn --chdir="$tmp/sites" --bind=0.0.0.0:9090 --threads=4 --workers=2 --worker-class=gthread --worker-tmp-dir=/dev/shm --timeout=120 --preload frappe.app:application
'';
}