From b5365ffb3cd7b406a0199f0c09316613f79c15f7 Mon Sep 17 00:00:00 2001 From: Akshay Mankar Date: Sun, 21 May 2023 20:20:59 +0200 Subject: [PATCH] wip: assets compile, run script still doesn't work --- flake.nix | 25 +++++++-- node/frappe-assets.nix | 98 ++++++++++++++++++++++++++++++++++ python/erpnext.nix | 117 +++-------------------------------------- python/frappe.nix | 7 +-- srcs/erpnext.nix | 7 +++ srcs/frappe.nix | 8 +++ 6 files changed, 142 insertions(+), 120 deletions(-) create mode 100644 node/frappe-assets.nix create mode 100644 srcs/erpnext.nix create mode 100644 srcs/frappe.nix diff --git a/flake.nix b/flake.nix index 2f6666b..aad1858 100644 --- a/flake.nix +++ b/flake.nix @@ -6,8 +6,7 @@ inputs.pip2nix = { url = "github:nix-community/pip2nix"; flake = false; - # inputs.nixpkgs.follows = "nixpkgs"; - # inputs.flake-utils.follows = "flake-utils"; + # inputs.nixpkgs.follows = "nixpkgs"; # inputs.flake-utils.follows = "flake-utils"; }; outputs = {nixpkgs, flake-utils, pip2nix, ...}: @@ -26,12 +25,30 @@ #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} - ${penv}/bin/gunicorn --bind=0.0.0.0:9090 --threads=4 --workers=2 --worker-class=gthread --worker-tmp-dir=/dev/shm --timeout=120 --preload frappe.app:application + sites=$(mktemp -d) + for f in ${assets}/share/sites/*; do + ln -s "$f" "$sites/$(basename $f)" + done + cat >$sites/common_site_config.json < sites/apps.txt + + cp -r ${erpnextSrc} apps/erpnext + cp -r $src apps/frappe + + chmod u+rw apps/erpnext + chmod u+rw apps/frappe + chmod -R u+rw sites/assets/erpnext + chmod -R u+rw sites/assets/frappe + + cp -r ${erpnext-modules}/node_modules apps/erpnext/node_modules + cp -r $node_modules apps/frappe/node_modules + + yarn --offline production + mv sites deps/ + + runHook postBuild + ''; + + # Do not attempt generating a tarball + doDist = false; + }; + frappe-assets = stdenv.mkDerivation { + pname = "erpnext-assets"; + version = "14.24.3"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/share + cp -r "${frappe-modules}/libexec/frappe-framework/deps/sites/" $out/share/sites + ''; + }; +in frappe-assets diff --git a/python/erpnext.nix b/python/erpnext.nix index c304bd6..7bd7527 100644 --- a/python/erpnext.nix +++ b/python/erpnext.nix @@ -16,20 +16,11 @@ , python-stdnum , frappe }: -let - frappe-version = "14.36.1"; - erpnext-version = "14.24.3"; -in buildPythonPackage rec { pname = "erpnext"; - version = erpnext-version; + version = "14.24.3"; format = "flit"; - src = fetchFromGitHub { - owner = "frappe"; - repo = pname; - rev = "v${erpnext-version}"; - sha256 = "sha256-zovdbpTp9fTpY7kAs4J8EiPh+EjqUOtVUk+rDYMfYDk="; - }; + src = import ../srcs/erpnext.nix {inherit fetchFromGitHub; }; propagatedBuildInputs = [ taxjar gocardless-pro @@ -44,103 +35,9 @@ buildPythonPackage rec { frappe ]; - frappe-assets = mkYarnPackage { - pname = "frappe-assets"; - version = frappe-version; - - src = fetchFromGitHub { - owner = "frappe"; - repo = "frappe"; - rev = "v${frappe-version}"; - hash = "sha256-eee6IS/Ep/DSDCPdnyrqBea/ag0kNnN5Id3YQMNz5js="; - }; - - packageJSON = ../frappe-package.json; - yarnFlags = [ "--production" ]; - - offlineCache = fetchYarnDeps { - yarnLock = src + "/yarn.lock"; - hash = "sha256-PBdMUz9gJIoQaqQYbdk+xnd8CyZPmdeyz/9WznCb4Ss="; - }; - - buildPhase = '' - runHook preBuild - # Yarn writes cache directories etc to $HOME. - export HOME=$PWD/yarn_home - - # The upstream build script reads sites/apps.txt to define what assets to build - # A list of assets is written to sites/assets/assets.json - mkdir -p apps sites/assets - echo -e "erpnext\nfrappe\n" > sites/apps.txt - cp -r ${src} apps/erpnext - chmod u+rw apps/erpnext - cp -r ${erpnext-modules}/node_modules apps/erpnext/node_modules - chmod u+rw apps/erpnext - #ln -s ${frappe-assets.src} apps/frappe - - yarn --offline production - mv sites deps/ - - runHook postBuild - ''; - - # Do not attempt generating a tarball - doDist = false; - - meta = with lib; { - description = "Assets for frappe"; - homepage = "https://github.com/frappe/frappe"; - license = licenses.mit; - maintainers = with maintainers; [ axeman teutat3s ]; - }; - }; - erpnext-modules = mkYarnPackage { - pname = "erpnext-modules"; - version = erpnext-version; - - src = fetchFromGitHub { - owner = "frappe"; - repo = "erpnext"; - rev = "v${erpnext-version}"; - hash = "sha256-zovdbpTp9fTpY7kAs4J8EiPh+EjqUOtVUk+rDYMfYDk="; - }; - - packageJSON = ../erpnext-package.json; - yarnFlags = [ "--production" ]; - - offlineCache = fetchYarnDeps { - yarnLock = ../erpnext-yarn.lock; - hash = "sha256-Vho4BSbxcsVYExLvUaeoc3xIpbXoCUP/4jw4RwGnWGY="; - }; - - configurePhase = '' - ln -s $node_modules node_modules - ''; - - installPhase = '' - ls -alh - mkdir $out - cp -r node_modules $out/ - ls -alh $out/ - ''; - - # We only need node_modules - dontBuild = true; - - # Do not attempt generating a tarball - doDist = false; - - meta = with lib; { - description = "Node modules for erpnext"; - homepage = "https://github.com/frappe/erpnext"; - license = licenses.mit; - maintainers = with maintainers; [ axeman teutat3s ]; - }; - }; - - postInstall = '' - mkdir -p $out/test/frappe $out/test/erpnext - ln -s ${frappe-assets} $out/test/frappe - ln -s ${erpnext-modules} $out/test/erpnext - ''; + # postInstall = '' + # mkdir -p $out/test/frappe $out/test/erpnext + # ln -s ${frappe-assets} $out/test/frappe + # ln -s ${erpnext-modules} $out/test/erpnext + # ''; } diff --git a/python/frappe.nix b/python/frappe.nix index 7c44f03..0bc10ea 100644 --- a/python/frappe.nix +++ b/python/frappe.nix @@ -83,12 +83,7 @@ buildPythonPackage rec { pname = "frappe"; version = "14.36.1"; format = "flit"; - src = fetchFromGitHub { - owner = "akshaymankar"; - repo = "frappe"; - rev = "d4d3cbc12d3e40f104500866a2bf468d128e2e32"; - sha256 = "sha256-+z/IeK3bFGYxnvWCR6GTgik25lSReJvRCbV7MsoUA/g="; - }; + src = import ../srcs/frappe.nix { inherit fetchFromGitHub; } ; propagatedBuildInputs = [ babel click diff --git a/srcs/erpnext.nix b/srcs/erpnext.nix new file mode 100644 index 0000000..b7ff5d2 --- /dev/null +++ b/srcs/erpnext.nix @@ -0,0 +1,7 @@ +{fetchFromGitHub}: +fetchFromGitHub { + owner = "frappe"; + repo = "erpnext"; + rev = "v14.24.3"; + sha256 = "sha256-zovdbpTp9fTpY7kAs4J8EiPh+EjqUOtVUk+rDYMfYDk="; +} diff --git a/srcs/frappe.nix b/srcs/frappe.nix new file mode 100644 index 0000000..17b4502 --- /dev/null +++ b/srcs/frappe.nix @@ -0,0 +1,8 @@ +{fetchFromGitHub}: + +fetchFromGitHub { + owner = "akshaymankar"; + repo = "frappe"; + rev = "d4d3cbc12d3e40f104500866a2bf468d128e2e32"; + sha256 = "sha256-+z/IeK3bFGYxnvWCR6GTgik25lSReJvRCbV7MsoUA/g="; +}