about summary refs log tree commit diff
path: root/pkgs/by-name/cr/crabfit-frontend/package.nix
blob: 24ad597d40cb6222fbf45b98ae85f3ed12c575a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
  lib,
  nixosTests,
  stdenv,
  fetchFromGitHub,
  fetchYarnDeps,
  fetchpatch,
  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 = "0-unstable-2023-08-02";

  src = fetchFromGitHub {
    owner = "GRA0007";
    repo = "crab.fit";
    rev = "628f9eefc300bf1ed3d6cc3323332c2ed9b8a350";
    hash = "sha256-jy8BrJSHukRenPbZHw4nPx3cSi7E2GSg//WOXDh90mY=";
  };

  sourceRoot = "source/frontend";

  patches = [
    ./01-localfont.patch
    (fetchpatch {
      name = "02-standalone-app.patch";
      url = "https://github.com/GRA0007/crab.fit/commit/6dfd69cd59784932d195370eb3c5c87589609c9f.patch";
      relative = "frontend";
      hash = "sha256-XV7ia+flcUU6sLHdrMjkPV7kWymfxII7bpoeb/LkMQE=";
    })
    ./03-frontend-url.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-fail "@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
  '';

  passthru.tests = [ nixosTests.crabfit ];

  meta = {
    description = "Enter your availability to find a time that works for everyone";
    homepage = "https://github.com/GRA0007/crab.fit";
    license = lib.licenses.gpl3;
    maintainers = with lib.maintainers; [ thubrecht ];
  };
})