]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - virtual/modules/websites/aten/aten.nix
Purify aten's website
[perso/Immae/Config/Nix.git] / virtual / modules / websites / aten / aten.nix
index 1520439e349eef427dd248c00203e7ab64ffe6f0..69e1d4c37409cee35bf0ee9cf415da9e53666aea 100644 (file)
@@ -1,4 +1,4 @@
-{ lib, writeText, fetchedGitPrivate, stdenv, php, git, cacert, phpPackages, yarn }:
+{ lib, writeText, fetchedGitPrivate, stdenv, composerEnv, fetchurl, fetchgit, binutils, python, nodejs, libsass, yarn2nix }:
 let
   aten = { config }: rec {
     environment = config.environment;
@@ -87,31 +87,49 @@ let
       fi
       '';
     };
-    webappDir = stdenv.mkDerivation (fetchedGitPrivate ./aten.json // rec {
-      buildPhase = ''
-        export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
-        export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
-        export APP_ENV="${environment}"
-        export DATABASE_URL="${config.psql_url}"
-        export APP_SECRET="${config.secret}"
-
-        ${if environment == "dev" then ''
-          composer install
-        '' else ''
-          SYMFONY_ENV=prod composer install --no-dev
-        ''}
-        yarn install
-        yarn run encore production
-        rm -rf var
-        ln -sf ../../../../../${varDir} var
-        '';
-      installPhase = ''
-        cp -a . $out
-        '';
-      buildInputs = [
-        php git cacert phpPackages.composer yarn
-      ];
-    });
+    yarnModules = let
+        info = fetchedGitPrivate ./aten.json;
+      in
+        yarn2nix.mkYarnModules {
+          name = "aten-yarn-modules";
+          packageJSON = "${info.src}/package.json";
+          yarnLock = "${info.src}/yarn.lock";
+          pkgConfig = {
+            node-sass = {
+              buildInputs = [ binutils libsass python ];
+              postInstall = let
+                nodeHeaders = fetchurl {
+                  url = "https://nodejs.org/download/release/v${nodejs.version}/node-v${nodejs.version}-headers.tar.gz";
+                  sha256 = "12zzsf8my43b8qnlacp871ih5vqafl2vlpqp51xp6h3gckn2frwy";
+                };
+              in
+                ''
+                  export AR=${binutils.bintools}/bin/ar
+                  node scripts/build.js --tarball=${nodeHeaders}
+                '';
+            };
+          };
+        };
+    webappDir = composerEnv.buildPackage (
+      import ./php-packages.nix { inherit composerEnv fetchurl fetchgit; } //
+      fetchedGitPrivate ./aten.json //
+      rec {
+        noDev = (environment == "prod");
+        preInstall = ''
+          export SYMFONY_ENV="${environment}"
+          export APP_ENV="${environment}"
+          export DATABASE_URL="${config.psql_url}"
+          export APP_SECRET="${config.secret}"
+          '';
+        postInstall = ''
+          cd $out
+          ln -sf ${yarnModules}/node_modules .
+          yarn run --offline encore production
+          rm -rf var/{log,cache}
+          ln -sf ../../../../../../../${varDir}/{log,cache} var/
+          '';
+        buildInputs = [ yarn2nix.yarn ];
+      });
     webRoot = "${webappDir}/public";
   };
 in