]> Untitled Git - lemmy-ui.git/blob - default.nix
f78b8ef6674c213468083e3ec2916ec20b6398e2
[lemmy-ui.git] / default.nix
1 { lib, mkYarnPackage, libsass, nodejs, python3, pkg-config, fetchFromGitHub
2 , fetchYarnDeps, nixosTests, vips, nodePackages, lemmy-translations
3 , lemmy-js-client }:
4
5 let
6   pkgConfig = {
7     node-sass = {
8       nativeBuildInputs = [ pkg-config ];
9       buildInputs = [ libsass python3 ];
10       postInstall = ''
11         LIBSASS_EXT=auto yarn --offline run build
12         rm build/config.gypi
13       '';
14     };
15     sharp = {
16       nativeBuildInputs = [ pkg-config nodePackages.semver ];
17       buildInputs = [ vips ];
18       postInstall = ''
19         yarn --offline run install
20       '';
21     };
22   };
23
24   name = "lemmy-ui";
25   version = "0.18.4";
26
27   src = ./.;
28
29 in mkYarnPackage {
30
31   inherit src pkgConfig name version;
32
33   extraBuildInputs = [ libsass ];
34
35   packageJSON = ./package.json;
36   offlineCache = fetchYarnDeps {
37     yarnLock = src + "/yarn.lock";
38     sha256 = "sha256-fRJpA9WstNNNOePoqotJKYmlikkcjc34iM0WO8+a/3Q=";
39   };
40
41   yarnPreBuild = ''
42     export npm_config_nodedir=${nodejs}
43   '';
44
45   buildPhase = ''
46     # Yarn writes cache directories etc to $HOME.
47     export HOME=$PWD/yarn_home
48     rm -rf node_modules/lemmy-js-client
49     ln -sf ${lemmy-js-client}/libexec/lemmy-js-client/node_modules/lemmy-js-client node_modules/lemmy-js-client
50
51     ln -sf $PWD/node_modules $PWD/deps/lemmy-ui/
52     echo 'export const VERSION = "${version}";' > $PWD/deps/lemmy-ui/src/shared/version.ts
53
54     ln -sf ${lemmy-translations} deps/lemmy-ui/lemmy-translations
55
56     yarn --offline build:prod
57   '';
58
59   preInstall = ''
60     mkdir $out
61     cp -R ./deps/lemmy-ui/dist $out
62     cp -R ./node_modules $out
63   '';
64
65   distPhase = "true";
66
67   passthru.updateScript = ./update.sh;
68   passthru.tests.lemmy-ui = nixosTests.lemmy;
69
70   meta = with lib; {
71     description = "Building a federated alternative to reddit in rust";
72     homepage = "https://join-lemmy.org/";
73     license = licenses.agpl3Only;
74     maintainers = with maintainers; [ happysalada billewanick ];
75     inherit (nodejs.meta) platforms;
76   };
77 }