erpnext-nix/flake.nix
2023-05-22 19:26:55 +02:00

71 lines
2.8 KiB
Nix

{
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";
};
outputs = {nixpkgs, flake-utils, pip2nix, ...}:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system;
config.allowBroken = true;
};
#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 {};
penv = py.buildEnv.override {
extraLibs = [ py.pkgs.frappe py.pkgs.erpnext ];
};
runErpNext = pkgs.writeShellScriptBin "runErpNext" ''
export PYTHON_PATH=${penv}/${py.sitePackages}
hostname=localhost
sites=$(mktemp -d)
for f in ${assets}/share/sites/*; do
ln -s "$f" "$sites/$(basename $f)"
done
cat >$sites/common_site_config.json <<EOF
{
"db_host": "localhost",
"db_port": 3306,
"db_name": "erpnext" ,
"db_password": "erpnext" ,
"redis_cache": "redis://localhost",
"redis_queue": "redis://localhost",
"redis_socketio": "redis://localhost",
"socketio_port": 6379
}
EOF
mkdir -p $sites/$hostname/logs
ln -s $sites/common_site_config.json $sites/$hostname/site_config.json
echo "Sites dir: $sites"
${penv}/bin/gunicorn --chdir="$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
'';
in rec {
packages = {
devEnv = pkgs.buildEnv {
name = "erpnext-nix-dev-env";
paths = [
pkgs.dasel
];
};
inherit pkgs runErpNext assets;
pip2nix = import "${pip2nix}/default.nix" { inherit pkgs; pythonPackages = "python310Packages"; };
erpnext = py.pkgs.erpnext;
pythonPkgs = py.pkgs;
};
});
}