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

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

  name = "lemmy-ui";
  version = "0.12.2";
  unwrapped = mkYarnPackage {

    src = fetchFromGitHub {
      owner = "LemmyNet";
      repo = name;
      rev = version;
      fetchSubmodules = true;
      sha256 = "sha256-iFLJqUnz4m9/JTSaJSUugzY5KkiKtH0sMYY4ALm2Ebk=";
    };

    inherit pkgConfig name version;

    extraBuildInputs = [ libsass ];

    yarnNix = ./yarn.nix;

    # Fails mysteriously on source/package.json
    # Upstream package.json is missing a newline at the end
    packageJSON = ./package.json;

    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/

      yarn --offline build:prod
    '';

    distPhase = "true";

    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 ];
      platforms = platforms.linux;
    };
  };
in
(writeShellScriptBin "lemmy-ui" ''
  ${nodejs}/bin/node ${unwrapped}/libexec/lemmy-ui/node_modules/lemmy-ui/dist/js/server.js
'').overrideAttrs (oldAttrs: {
  passthru = { inherit unwrapped; };
})