about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/web-apps/lemmy/ui.nix
blob: 4f219ae21abaf89a7f3027a5184d480f73c7c454 (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
{ lib
, mkYarnPackage
, libsass
, nodejs
, python3
, pkg-config
, fetchFromGitHub
, fetchYarnDeps
, nixosTests
, vips
, nodePackages
}:

let
  pinData = lib.importJSON ./pin.json;

  pkgConfig = {
    node-sass = {
      nativeBuildInputs = [ pkg-config ];
      buildInputs = [ libsass python3 ];
      postInstall = ''
        LIBSASS_EXT=auto yarn --offline run build
        rm build/config.gypi
      '';
    };
    sharp = {
      nativeBuildInputs = [ pkg-config nodePackages.node-gyp nodePackages.semver ];
      buildInputs = [ vips ];
      postInstall = ''
        yarn --offline run install
      '';
    };
  };

  name = "lemmy-ui";
  version = pinData.uiVersion;

  src = fetchFromGitHub {
    owner = "LemmyNet";
    repo = name;
    rev = version;
    fetchSubmodules = true;
    hash = pinData.uiHash;
  };
in
mkYarnPackage {

  inherit src pkgConfig name version;

  extraBuildInputs = [ libsass ];

  packageJSON = ./package.json;
  offlineCache = fetchYarnDeps {
    yarnLock = src + "/yarn.lock";
    hash = pinData.uiYarnDepsHash;
  };

  patchPhase = ''
    substituteInPlace ./package.json \
      --replace '$(git rev-parse --short HEAD)' "${src.rev}" \
      --replace 'yarn clean' 'yarn --offline clean' \
      --replace 'yarn run rimraf dist' 'yarn --offline run rimraf dist'
  '';

  yarnPreBuild = ''
    export npm_config_nodedir=${nodejs}
  '';

  buildPhase = ''
    # Yarn writes cache directories etc to $HOME.
    export HOME=$PWD/yarn_home

    ln -sf $PWD/node_modules $PWD/deps/lemmy-ui/
    echo 'export const VERSION = "${version}";' > $PWD/deps/lemmy-ui/src/shared/version.ts

    yarn --offline build:prod
  '';

  preInstall = ''
    mkdir $out
    cp -R ./deps/lemmy-ui/dist $out
    cp -R ./node_modules $out
  '';

  distPhase = "true";

  passthru.updateScript = ./update.py;
  passthru.tests.lemmy-ui = nixosTests.lemmy;
  passthru.commit_sha = src.rev;

  meta = with lib; {
    description = "Building a federated alternative to reddit in rust";
    homepage = "https://join-lemmy.org/";
    license = licenses.agpl3Only;
    maintainers = with maintainers; [ happysalada billewanick adisbladis ];
    inherit (nodejs.meta) platforms;
  };
}