infrastructure/machines/web01/crabfit/packages/crabfit-frontend/default.nix

114 lines
2.9 KiB
Nix

{
lib,
stdenv,
fetchFromGitHub,
fetchYarnDeps,
nodejs,
yarn,
fixup_yarn_lock,
google-fonts,
api_url ? "http://127.0.0.1:3000",
frontend_url ? "crab.fit",
}:
stdenv.mkDerivation (
finalAttrs: {
pname = "crabfit-frontend";
version = "unstable-2023-08-02";
src = fetchFromGitHub {
owner = "GRA0007";
repo = "crab.fit";
rev = "628f9eefc300bf1ed3d6cc3323332c2ed9b8a350";
hash = "sha256-jy8BrJSHukRenPbZHw4nPx3cSi7E2GSg//WOXDh90mY=";
};
sourceRoot = "source/frontend";
patches = [
./01-privacy.patch
./02-karla.patch
./03-standalone.patch
./04-frontend_url.patch
./05-dgnum.patch
./06-download.patch
];
offlineCache = fetchYarnDeps {
yarnLock = "${finalAttrs.src}/frontend/yarn.lock";
hash = "sha256-jkyQygwHdLlEZ1tlSQOh72nANp2F29rZbTXvKQStvGc=";
};
nativeBuildInputs = [
nodejs
yarn
fixup_yarn_lock
];
postPatch = ''
substituteInPlace \
public/robots.txt \
public/sitemap.xml \
src/app/\[id\]/page.tsx \
src/app/layout.tsx \
src/components/CreateForm/components/EventInfo/EventInfo.tsx \
src/i18n/locales/de/help.json \
src/i18n/locales/en-GB/help.json \
src/i18n/locales/en/help.json \
src/i18n/locales/es/help.json \
src/i18n/locales/fr/help.json \
src/i18n/locales/hi/help.json \
src/i18n/locales/id/help.json \
src/i18n/locales/it/help.json \
src/i18n/locales/ko/help.json \
src/i18n/locales/pt-BR/help.json \
src/i18n/locales/pt-PT/help.json \
src/i18n/locales/ru/help.json \
--replace "@FRONTEND_URL@" "${frontend_url}"
'';
configurePhase = ''
runHook preConfigure
export HOME="$PWD"
echo 'NEXT_PUBLIC_API_URL="${api_url}"' > .env.local
fixup_yarn_lock yarn.lock
yarn config --offline set yarn-offline-mirror ${finalAttrs.offlineCache}
yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
patchShebangs node_modules
mkdir -p src/app/fonts
cp "${
google-fonts.override { fonts = [ "Karla" ]; }
}/share/fonts/truetype/Karla[wght].ttf" src/app/fonts/karla.ttf
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
NODE_ENV=production yarn build
runHook postBuild
'';
installPhase = ''
mkdir $out
cp -R .next/* $out
cp -R public $out/standalone/
cp -R .next/static $out/standalone/.next
ln -s /var/cache/crabfit $out/standalone/.next/cache
'';
meta = with lib; {
description = "Enter your availability to find a time that works for everyone";
homepage = "https://github.com/GRA0007/crab.fit";
license = licenses.gpl3;
maintainers = with maintainers; [ thubrecht ];
};
}
)