erpnext-nix/flake.nix

96 lines
3.9 KiB
Nix
Raw Normal View History

2023-05-18 13:57:22 +00:00
{
description = "Dev Setup";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.pip2nix = {
url = "github:nix-community/pip2nix";
flake = false;
# inputs.nixpkgs.follows = "nixpkgs"; # inputs.flake-utils.follows = "flake-utils";
2023-05-18 13:57:22 +00:00
};
outputs = {nixpkgs, flake-utils, pip2nix, ...}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system;
config.allowBroken = true;
};
2023-05-20 21:36:21 +00:00
#attrsets = pkgs.lib.attrsets;
#overrideFiles = (attrsets.filterAttrs (f: type: type == "regular") (builtins.readDir ./python));
#overridePackageNames = attrsets.mapAttrsToList (f: _: builtins.replaceStrings [".nix"] [""] f) overrideFiles;
py = pkgs.callPackage ./python.nix { inherit pkgs; };
# packageOverrides = pself: psuper:
# attrsets.genAttrs overridePackageNames (o: pself.callPackage ./python/${o}.nix {});
#});
#newversion = python3.pkgs.newversion.overrideAttrs(old: {
# propagatedBuildInputs = old.propagatedBuildInputs ++ [python3.pkgs.setuptools];
#});
assets = pkgs.callPackage ./node/frappe-assets.nix {};
# Source: https://github.com/frappe/frappe_docker/blob/main/resources/nginx-template.conf
nginx-conf = pkgs.callPackage ./nginx-erpnext-conf.nix {inherit pkgs;};
2023-05-21 15:55:26 +00:00
penv = py.buildEnv.override {
extraLibs = [ py.pkgs.frappe py.pkgs.erpnext ];
};
erpnextSrc = pkgs.callPackage ./srcs/erpnext.nix {};
frappeModules = pkgs.callPackage ./node/frappe-modules.nix {};
2023-05-21 15:55:26 +00:00
runErpNext = pkgs.writeShellScriptBin "runErpNext" ''
export PYTHON_PATH=${penv}/${py.sitePackages}
# The upstream installer bench CLI wants mysql in its PATH
export PATH=${pkgs.mariadb-client}/bin:''$PATH
2023-05-22 17:26:55 +00:00
hostname=localhost
tmp=/tmp/erpnext
mkdir -p $tmp/apps $tmp/sites $tmp/config/pids $tmp/logs/nginx $tmp/env/bin
for f in ${assets}/share/sites/*; do
ln -s "$f" "$tmp/sites/$(basename $f)"
done
cat >$tmp/sites/common_site_config.json <<EOF
{
2023-05-22 17:26:55 +00:00
"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
# The upstream bench CLI installer expects this file
echo -e "erpnext\nfrappe\n" > $tmp/sites/apps.txt
ln -s ${erpnextSrc} $tmp/apps/erpnext
ln -s ${frappeModules}/libexec/frappe-framework/deps/frappe-framework $tmp/apps/frappe
ln -s ${penv} $tmp/env
ln -sf ${nginx-conf} $tmp/nginx-erpnext.conf
cd $tmp
# Upstream initializes the DB with this command
${py.pkgs.bench}/bin/bench new-site localhost --mariadb-root-password password --admin-password admin
echo "Workdir: $tmp"
${pkgs.nodejs}/bin/node $tmp/apps/frappe/socketio.js &
${penv}/bin/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
2023-05-21 15:55:26 +00:00
'';
2023-05-18 13:57:22 +00:00
in rec {
packages = {
devEnv = pkgs.buildEnv {
name = "erpnext-nix-dev-env";
paths = [
pkgs.dasel
];
};
inherit pkgs runErpNext assets;
2023-05-18 13:57:22 +00:00
pip2nix = import "${pip2nix}/default.nix" { inherit pkgs; pythonPackages = "python310Packages"; };
2023-05-20 21:36:21 +00:00
erpnext = py.pkgs.erpnext;
bench = py.pkgs.bench;
2023-05-20 21:36:21 +00:00
pythonPkgs = py.pkgs;
2023-05-18 13:57:22 +00:00
};
});
}