{ 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 {}; # Source: https://github.com/frappe/frappe_docker/blob/main/resources/nginx-template.conf nginx-conf = pkgs.callPackage ./nginx-erpnext-conf.nix {inherit pkgs;}; penv = py.buildEnv.override { extraLibs = [ py.pkgs.frappe py.pkgs.erpnext ]; }; 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 hostname=localhost tmp=/tmp/erpnext mkdir -p $tmp/apps $tmp/sites $tmp/config/pids $tmp/logs $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 < $tmp/sites/apps.txt cd $tmp ln -s ${py.pkgs.erpnext}/lib/python3.10/site-packages apps/erpnext ln -s ${py.pkgs.frappe}/lib/python3.10/site-packages apps/frappe ln -s ${penv} $tmp/env ln -sf ${nginx-conf} $tmp/nginx-erpnext.conf # 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" ${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 ''; 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; bench = py.pkgs.bench; pythonPkgs = py.pkgs; }; }); }