Skip to content

Commit

Permalink
hedgedoc: 1.9.7 -> 1.9.8 and redo package
Browse files Browse the repository at this point in the history
- Yarnify
- Do a full source build
- Clean up the wrapper things
  • Loading branch information
dasJ authored and WilliButz committed Aug 1, 2023
1 parent d83fe33 commit 81a8190
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 285 deletions.
107 changes: 66 additions & 41 deletions pkgs/servers/web-apps/hedgedoc/default.nix
Original file line number Diff line number Diff line change
@@ -1,76 +1,101 @@
{ lib
, stdenv
, fetchzip
, makeWrapper
, which
, fetchFromGitHub
, gitMinimal
, cacert
, yarn
, makeBinaryWrapper
, nodejs
, mkYarnPackage
, fetchYarnDeps
, python3
, nixosTests
}:

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

# 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-tPkhnnKDS5TICsW66YCOy7xWFj5usLyDMbYMYQ3Euoc=";
let
version = "1.9.8";

src = fetchFromGitHub {
owner = "hedgedoc";
repo = "hedgedoc";
rev = version;
hash = "sha256-gp1TeYHwH7ffaSMifdURb2p+U8u6Xs4JU4b4qACEIDw=";
};

nativeBuildInputs = [ which makeWrapper ];
extraBuildInputs = [ python3 ];
# we cannot use fetchYarnDeps because that doesn't support yarn 2/berry lockfiles
offlineCache = stdenv.mkDerivation {
name = "hedgedoc-${version}-offline-cache";
inherit src;

nativeBuildInputs = [
cacert # needed for git
gitMinimal # needed to download git dependencies
nodejs # needed for npm to download git dependencies
yarn
];

buildPhase = ''
export HOME=$(mktemp -d)
yarn config set enableTelemetry 0
yarn config set cacheFolder $out
yarn config set --json supportedArchitectures.os '[ "linux" ]'
yarn config set --json supportedArchitectures.cpu '["arm", "arm64", "ia32", "x64"]'
yarn
'';

outputHashMode = "recursive";
outputHash = "sha256-/jsBFGH/rYSovidmvIf7xpuHpxdW8QFYC08PNi38LH8=";
};

packageJSON = ./package.json;
yarnFlags = [ "--production" ];
in stdenv.mkDerivation {
pname = "hedgedoc";
inherit version src;

offlineCache = fetchYarnDeps {
yarnLock = src + "/yarn.lock";
sha256 = "0qkc26ks33vy00jgpv4445wzgxx1mzi70pkm1l8y9amgd9wf9aig";
};
nativeBuildInputs = [
makeBinaryWrapper
yarn
python3 # needed for sqlite node-gyp
];

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

buildPhase = ''
runHook preBuild
pushd node_modules/sqlite3
export HOME=$(mktemp -d)
yarn config set enableTelemetry 0
yarn config set cacheFolder ${offlineCache}
# This will fail but create the sqlite3 files we can patch
yarn --immutable-cache || :
# Ensure we don't download any node things
sed -i 's:--fallback-to-build:--build-from-source --nodedir=${nodejs}/include/node:g' node_modules/sqlite3/package.json
export CPPFLAGS="-I${nodejs}/include/node"
npm run install --build-from-source --nodedir=${nodejs}/include/node
popd
# Perform the actual install
yarn --immutable-cache
yarn run build
patchShebangs bin/*
runHook postBuild
'';

dontInstall = true;

distPhase = ''
runHook preDist
installPhase = ''
runHook preInstall
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 \
makeWrapper ${nodejs}/bin/node $out/bin/hedgedoc \
--add-flags $out/app.js \
--set NODE_ENV production \
--set NODE_PATH "$out/lib/node_modules"
runHook postDist
runHook postInstall
'';

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

Expand Down
213 changes: 0 additions & 213 deletions pkgs/servers/web-apps/hedgedoc/package.json

This file was deleted.

31 changes: 0 additions & 31 deletions pkgs/servers/web-apps/hedgedoc/update.sh

This file was deleted.

0 comments on commit 81a8190

Please sign in to comment.