summary refs log tree commit diff
path: root/pkgs/servers/web-apps/hedgedoc/default.nix
blob: f6c8a8c47d5d4e6c480302cdce3276fa7da1a990 (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
{ lib
, stdenv
, fetchzip
, makeWrapper
, which
, nodejs
, mkYarnPackage
, fetchYarnDeps
, python3
, nixosTests
}:

mkYarnPackage rec {
  pname = "hedgedoc";
  version = "1.9.5";

  # we use the upstream compiled js files because yarn2nix cannot handle different versions of dependencies
  # in development and production and the web assets muts be compiled with js-yaml 3 while development
  # uses js-yaml 4 which breaks the text editor
  src = fetchzip {
    url = "https://github.com/hedgedoc/hedgedoc/releases/download/${version}/hedgedoc-${version}.tar.gz";
    hash = "sha256-dcqCc4UUI1knRlDfQlXq3cpTRTh+kbgFynbypDzw9y8=";
  };

  nativeBuildInputs = [ which makeWrapper ];
  extraBuildInputs = [ python3 ];

  packageJSON = ./package.json;
  yarnFlags = [ "--production" ];

  offlineCache = fetchYarnDeps {
    yarnLock = src + "/yarn.lock";
    sha256 = "18k2q2llngdk0gsyjrwpirhvwmkwgzhx8nw1rx7g7v2nfzyz189b";
  };

  configurePhase = ''
    cp -r "$node_modules" node_modules
    chmod -R u+w node_modules
  '';

  buildPhase = ''
    runHook preBuild

    pushd node_modules/sqlite3
    export CPPFLAGS="-I${nodejs}/include/node"
    npm run install --build-from-source --nodedir=${nodejs}/include/node
    popd

    patchShebangs bin/*

    runHook postBuild
  '';

  dontInstall = true;

  distPhase = ''
    runHook preDist

    mkdir -p $out
    cp -R {app.js,bin,lib,locales,node_modules,package.json,public} $out

    cat > $out/bin/hedgedoc <<EOF
      #!${stdenv.shell}/bin/sh
      ${nodejs}/bin/node $out/app.js
    EOF
    chmod +x $out/bin/hedgedoc
    wrapProgram $out/bin/hedgedoc \
      --set NODE_PATH "$out/lib/node_modules"

    runHook postDist
  '';

  passthru = {
    tests = { inherit (nixosTests) hedgedoc; };
  };

  meta = with lib; {
    description = "Realtime collaborative markdown notes on all platforms";
    license = licenses.agpl3;
    homepage = "https://hedgedoc.org";
    maintainers = with maintainers; [ willibutz SuperSandro2000 ];
    platforms = platforms.linux;
  };
}