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;
|
2023-05-21 18:20:59 +00:00
|
|
|
# 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];
|
|
|
|
#});
|
2023-05-21 18:20:59 +00:00
|
|
|
assets = pkgs.callPackage ./node/frappe-assets.nix {};
|
2023-05-22 22:50:17 +00:00
|
|
|
# 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 ];
|
|
|
|
};
|
2023-05-23 00:05:33 +00:00
|
|
|
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}
|
2023-05-22 22:50:17 +00:00
|
|
|
# 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
|
2023-05-22 22:50:17 +00:00
|
|
|
tmp=/tmp/erpnext
|
|
|
|
|
2023-05-23 00:05:33 +00:00
|
|
|
mkdir -p $tmp/apps $tmp/sites $tmp/config/pids $tmp/logs/nginx $tmp/env/bin
|
2023-05-22 22:50:17 +00:00
|
|
|
|
2023-05-21 18:20:59 +00:00
|
|
|
for f in ${assets}/share/sites/*; do
|
2023-05-22 22:50:17 +00:00
|
|
|
ln -s "$f" "$tmp/sites/$(basename $f)"
|
2023-05-21 18:20:59 +00:00
|
|
|
done
|
2023-05-22 22:50:17 +00:00
|
|
|
|
|
|
|
cat >$tmp/sites/common_site_config.json <<EOF
|
2023-05-21 18:20:59 +00:00
|
|
|
{
|
2023-05-22 17:26:55 +00:00
|
|
|
"db_host": "localhost",
|
|
|
|
"db_port": 3306,
|
|
|
|
"db_name": "erpnext" ,
|
|
|
|
"db_password": "erpnext" ,
|
2023-05-23 00:05:33 +00:00
|
|
|
"redis_cache": "redis://localhost:6379?db=0",
|
|
|
|
"redis_queue": "redis://localhost:6379?db=1",
|
|
|
|
"redis_socketio": "redis://localhost:6379?db=2",
|
|
|
|
"socketio_port": 3000
|
2023-05-21 18:20:59 +00:00
|
|
|
}
|
|
|
|
EOF
|
2023-05-22 22:50:17 +00:00
|
|
|
|
|
|
|
# The upstream bench CLI installer expects this file
|
|
|
|
echo -e "erpnext\nfrappe\n" > $tmp/sites/apps.txt
|
|
|
|
|
2023-05-23 00:05:33 +00:00
|
|
|
ln -s ${erpnextSrc} $tmp/apps/erpnext
|
|
|
|
ln -s ${frappeModules}/libexec/frappe-framework/deps/frappe-framework $tmp/apps/frappe
|
|
|
|
|
2023-05-22 22:50:17 +00:00
|
|
|
ln -s ${penv} $tmp/env
|
|
|
|
ln -sf ${nginx-conf} $tmp/nginx-erpnext.conf
|
|
|
|
|
2023-05-23 00:05:33 +00:00
|
|
|
cd $tmp
|
2023-05-22 22:50:17 +00:00
|
|
|
# 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"
|
2023-05-23 00:05:33 +00:00
|
|
|
${pkgs.nodejs}/bin/node $tmp/apps/frappe/socketio.js &
|
2023-05-22 22:50:17 +00:00
|
|
|
${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
|
|
|
|
];
|
|
|
|
};
|
2023-05-21 18:20:59 +00:00
|
|
|
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;
|
2023-05-22 22:50:17 +00:00
|
|
|
bench = py.pkgs.bench;
|
2023-05-20 21:36:21 +00:00
|
|
|
pythonPkgs = py.pkgs;
|
2023-05-18 13:57:22 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|