From 625e0bfd93fd32bc9b698f16f70a86dec0e1ef77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 23 Jan 2019 18:17:24 +0100 Subject: Purify aten's website --- virtual/modules/websites/aten/aten.nix | 70 +++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'virtual/modules/websites/aten/aten.nix') diff --git a/virtual/modules/websites/aten/aten.nix b/virtual/modules/websites/aten/aten.nix index 1520439..69e1d4c 100644 --- a/virtual/modules/websites/aten/aten.nix +++ b/virtual/modules/websites/aten/aten.nix @@ -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 -- cgit v1.2.3