erpnext-nix/node/erpnext-apps-sites.nix

73 lines
2.3 KiB
Nix
Raw Normal View History

{ fetchFromGitHub
, fetchYarnDeps
, runCommand
, nodejs
, yarn
, path
, nodePackages
}:
let
erpnextSrc = import ../srcs/erpnext.nix {inherit fetchFromGitHub; };
erpnextOfflineCache = fetchYarnDeps {
yarnLock = "${erpnextSrc}/yarn.lock";
sha256 = "sha256-Vho4BSbxcsVYExLvUaeoc3xIpbXoCUP/4jw4RwGnWGY=";
};
frappeSrc = import ../srcs/frappe.nix {inherit fetchFromGitHub; };
frappeOfflineCache = fetchYarnDeps {
yarnLock = "${frappeSrc}/yarn.lock";
sha256 = "sha256-PBdMUz9gJIoQaqQYbdk+xnd8CyZPmdeyz/9WznCb4Ss=";
};
# Copied from nixpkgs:pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix
fixup_yarn_lock = runCommand "fixup_yarn_lock" {buildInputs = [ nodejs ];} ''
mkdir -p $out/lib
mkdir -p $out/bin
cp ${path}/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/urlToName.js $out/lib/urlToName.js
cp ${path}/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js $out/bin/fixup_yarn_lock
patchShebangs $out
'';
mkApp = name: src: yarnOfflineCache: runCommand "${name}-app" {
buildInputs = [fixup_yarn_lock yarn nodePackages.node-gyp-build];
} ''
mkdir -p $out/share/apps
cp -r ${src} $out/share/apps/${name}
chmod -R +w $out/share/apps/${name}
export HOME=$(mktemp -d)
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
cd $out/share/apps/${name}
fixup_yarn_lock yarn.lock
yarn --offline --ignore-scripts install
'';
frappeApp = mkApp "frappe" frappeSrc frappeOfflineCache;
erpnextApp = mkApp "erpnext" erpnextSrc erpnextOfflineCache;
in runCommand "frappe-erpnext-apps-sites" {buildInputs = [yarn]; } ''
mkdir -p $out/share/sites $out/share/apps
# Cannot symlink because the code which traverses path to find sites
# directory gets confused.
cp -r ${frappeApp}/share/apps/frappe $out/share/apps/frappe
cp -r ${erpnextApp}/share/apps/erpnext $out/share/apps/erpnext
cat > $out/share/sites/apps.txt <<EOF
frappe
erpnext
EOF
cd $out/share/apps/frappe
yarn --offline production
symlinkPublic() {
find $out/share/apps/$1/$1/public -type d -mindepth 1 -maxdepth 1 | xargs -I '{}' bash -c "ln -s {} $out/share/sites/assets/$1/"'$(basename {})'
}
symlinkPublic frappe
symlinkPublic erpnext
''