about summary refs log tree commit diff
path: root/pkgs/servers/grocy/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/servers/grocy/default.nix')
-rw-r--r--pkgs/servers/grocy/default.nix65
1 files changed, 48 insertions, 17 deletions
diff --git a/pkgs/servers/grocy/default.nix b/pkgs/servers/grocy/default.nix
index 296aba9e1fb3..dbca9773ab65 100644
--- a/pkgs/servers/grocy/default.nix
+++ b/pkgs/servers/grocy/default.nix
@@ -1,40 +1,71 @@
-{ lib, stdenv, fetchurl, unzip, nixosTests }:
+{ lib
+, fetchFromGitHub
+, fetchYarnDeps
+, php
+, yarn
+, fixup-yarn-lock
+, nixosTests
+}:
 
-stdenv.mkDerivation rec {
+php.buildComposerProject (finalAttrs: {
   pname = "grocy";
-  version = "4.0.3";
+  version = "4.2.0";
 
-  src = fetchurl {
-    url = "https://github.com/grocy/grocy/releases/download/v${version}/grocy_${version}.zip";
-    hash = "sha256-KBTsi634SolgA01eRthMuWx7DIF7rhvJSPxiHyuKSR8=";
+  src = fetchFromGitHub {
+    owner = "grocy";
+    repo = "grocy";
+    rev = "v${finalAttrs.version}";
+    hash = "sha256-aX3DMy9Jv8rNp1/VIvUtNXYXGBrCgBMs5GsDf4XXSj0=";
   };
 
-  nativeBuildInputs = [ unzip ];
-  unpackPhase = ''
-    unzip ${src} -d .
-  '';
+  vendorHash = "sha256-KaYvA0Rd4pd1s/L8QbVUgkE+SjH+jv4+6RvIaGOpews=";
+
+  offlineCache = fetchYarnDeps {
+    yarnLock = finalAttrs.src + "/yarn.lock";
+    hash = "sha256-UvWY8+qSRvzJbm7z3CmLyeUHxemzNUB7dHYP95ZVtcI=";
+  };
+
+  nativeBuildInputs = [
+    yarn
+    fixup-yarn-lock
+  ];
+
+  # Upstream composer.json file is missing the name, description and license fields
+  composerStrictValidation = false;
 
   # NOTE: if patches are created from a git checkout, those should be modified
-  # with `unixdos` to make sure those apply here.
+  # with `unix2dos` to make sure those apply here.
   patches = [
     ./0001-Define-configs-with-env-vars.patch
     ./0002-Remove-check-for-config-file-as-it-s-stored-in-etc-g.patch
   ];
-  patchFlags = [ "--binary" "-p1" ];
 
-  dontBuild = true;
+  configurePhase = ''
+    runHook preConfigure
 
-  passthru.tests = { inherit (nixosTests) grocy; };
+    export HOME=$(mktemp -d)
+    yarn config --offline set yarn-offline-mirror $offlineCache
+    fixup-yarn-lock yarn.lock
+    yarn install --offline --frozen-lockfile --no-progress --non-interactive
+
+    runHook postConfigure
+  '';
 
   installPhase = ''
-    mkdir -p $out/
-    cp -R . $out/
+    runHook preInstall
+
+    mv $out/share/php/grocy/* $out
+    rm -r $out/share
+
+    runHook postInstall
   '';
 
+  passthru.tests = { inherit (nixosTests) grocy; };
+
   meta = with lib; {
     license = licenses.mit;
     maintainers = with maintainers; [ n0emis ];
     description = "ERP beyond your fridge - grocy is a web-based self-hosted groceries & household management solution for your home";
     homepage = "https://grocy.info/";
   };
-}
+})