aboutsummaryrefslogtreecommitdiff
path: root/cluster/prod/app/cryptpad/build/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'cluster/prod/app/cryptpad/build/default.nix')
-rw-r--r--cluster/prod/app/cryptpad/build/default.nix169
1 files changed, 105 insertions, 64 deletions
diff --git a/cluster/prod/app/cryptpad/build/default.nix b/cluster/prod/app/cryptpad/build/default.nix
index f0a5c00..ce694aa 100644
--- a/cluster/prod/app/cryptpad/build/default.nix
+++ b/cluster/prod/app/cryptpad/build/default.nix
@@ -1,77 +1,118 @@
-let
- common = import ./common.nix;
- pkgs = import common.pkgsSrc {};
- nodejs = pkgs.${common.nodejs};
-
- bower = (pkgs.buildBowerComponents {
- name = "cryptpad-${common.cryptpadVersion}-bower";
- generated = ./nix.lock/bower.nix;
- src = common.cryptpadSrc;
- }).overrideAttrs (old: {
- bowerPackages = old.bowerPackages.override (old_: {
- # add missing dependencies:
- # Those dependencies are EOL and they are not installed by buildBowerComponents,
- # but they are required, otherwise the resolver crashes.
- # * add the second jquery ~2.1.0 entry
- # * add the second bootstrap ~3.1.1 entry
- paths = old_.paths ++ [
- (pkgs.fetchbower "jquery" "2.1.0" "~2.1.0" "02kwvz93vzpv10qnp7s0dz3al0jh77awwrizb6wadsvgifxssnlr")
- (pkgs.fetchbower "bootstrap" "3.1.1" "~3.1.1" "06bhjwa8p7mzbpr3jkgydd804z1nwrkdql66h7jkfml99psv9811")
- ];
- });
- });
+{ lib
+, stdenvNoCC
+
+, buildNpmPackage
+, fetchFromGitHub
+
+, nodejs
- npm = import ./nix.lock/npm.nix {
- inherit pkgs;
+, withOnlyOffice ? true
+}: let
+ onlyOfficeVersions = {
+ v1 = {
+ rev = "4f370bebe96e3a0d4054df87412ee5b2c6ed8aaa";
+ hash = "sha256-TE/99qOx4wT2s0op9wi+SHwqTPYq/H+a9Uus9Zj4iSY=";
+ };
+ v2b = {
+ rev = "d9da72fda95daf93b90ffa345757c47eb5b919dd";
+ hash = "sha256-SiRDRc2vnLwCVnvtk+C8PKw7IeuSzHBaJmZHogRe3hQ=";
+ };
+ v4 = {
+ rev = "6ebc6938b6841440ffad2efc1e23f1dc1ceda964";
+ hash = "sha256-eto1+8Tk/s3kbUCpbUh8qCS8EOq700FYG1/KiHyynaA=";
+ };
+ v5 = {
+ rev = "88a356f08ded2f0f4620bda66951caf1d7f02c21";
+ hash = "sha256-8j1rlAyHlKx6oAs2pIhjPKcGhJFj6ZzahOcgenyeOCc=";
+ };
+ v6 = {
+ rev = "abd8a309f6dd37289f950cd8cea40df4492d8a15";
+ hash = "sha256-BZdExj2q/bqUD3k9uluOot2dlrWKA+vpad49EdgXKww=";
+ };
+ v7 = {
+ rev = "9d8b914a81f0f9e5d0bc3f0fc631adf4b6d480e7";
+ hash = "sha256-M+rPJ/Xo2olhqB5ViynGRaesMLLfG/1ltUoLnepMPnM=";
+ };
};
-
-in
- pkgs.stdenv.mkDerivation {
- name = "cryptpad-${common.cryptpadVersion}";
- src = common.cryptpadSrc;
-
- buildPhase = ''
- cp -r ${npm.nodeDependencies}/lib/node_modules node_modules
- chmod +w -R node_modules
-
- # clear executable files inside the node_modules folder to reduce dependencies
- # and attack surface
- find node_modules -type f ! -path 'node_modules/gar/*' -executable -print | tee >(xargs -n 20 rm)
-
- # Remove only office that IS BIG
- # COMMENTED as it is not as easy as planned.
- # rm -rf www/common/onlyoffice
- '';
+ mkOnlyOffice = {
+ pname, version
+ }: stdenvNoCC.mkDerivation (final: {
+ pname = "${pname}-onlyoffice";
+ inherit version;
+
+ srcs = lib.mapAttrsToList (version: { rev, hash ? lib.fakeHash }: fetchFromGitHub {
+ name = "${final.pname}-${version}-source";
+ owner = "cryptpad";
+ repo = "onlyoffice-builds";
+ inherit rev hash;
+ }) onlyOfficeVersions;
+
+ dontBuild = true;
+
+ sourceRoot = ".";
installPhase = ''
- mkdir -p $out/{bin,opt}
+ mkdir -p $out
+ ${lib.concatLines (map
+ (version: "cp -Tr ${final.pname}-${version}-source $out/${version}")
+ (builtins.attrNames onlyOfficeVersions)
+ )}
+ '';
+ });
+in buildNpmPackage rec {
+ pname = "cryptpad";
+ version = "2024.3.0";
- out_cryptpad=$out/opt/
+ src = fetchFromGitHub {
+ owner = "cryptpad";
+ repo = "cryptpad";
+ rev = version;
+ hash = "sha256-VUW6KvoSatk1/hlzklMQYlSNVH/tdbH+yU4ONUQ0JSQ=";
+ };
- # copy the source code
- cp -r .bowerrc bower.json package.json package-lock.json customize.dist lib server.js www $out_cryptpad
+ npmDepsHash = "sha256-tvTkoxxioPuNoe8KIuXSP7QQbvcpxMnygsMmzKBQIY0=";
- # mount node_modules
- cp -r node_modules $out_cryptpad/node_modules
+ inherit nodejs;
- # patch
- substituteInPlace $out_cryptpad/lib/workers/index.js --replace "lib/workers/db-worker" "$out_cryptpad/lib/workers/db-worker"
+ onlyOffice = lib.optional withOnlyOffice (mkOnlyOffice {
+ inherit pname version;
+ });
- # mount bower, based on the .bowerrc file at the git repo root
- cp -r ${bower}/bower_components $out_cryptpad/www/
+ makeCacheWritable = true;
+ dontFixup = true;
- # cryptpad is bugged with absolute path, this is a workaround to use absolute path as relative path
- ln -s / $out_cryptpad/root
+ postPatch = ''
+ cp -T ${./package-lock.json} package-lock.json
+ '';
- # start script, cryptpad is lost if its working directory is not its source directory
- cat > $out/bin/cryptpad <<EOF
- #!${pkgs.stdenv.shell}
- cd $out_cryptpad
- exec ${nodejs}/bin/node server.js
- EOF
+ preBuild = ''
+ npm run install:components
+ '' + lib.optionalString withOnlyOffice ''
+ ln -s $onlyOffice www/common/onlyoffice/dist
+ '';
- chmod +x $out/bin/cryptpad
- '';
+ postBuild = ''
+ rm -rf customize
+ '';
+
+ installPhase = ''
+ runHook preInstall
+
+ mkdir -p $out
+ cp -R . $out/
- dontFixup = true;
- }
+ substituteInPlace $out/lib/workers/index.js \
+ --replace-warn "lib/workers/db-worker" "$out/lib/workers/db-worker"
+
+ makeWrapper ${lib.getExe nodejs} $out/bin/cryptpad-server \
+ --chdir $out \
+ --add-flags server.js
+
+ runHook postInstall
+ '';
+
+ meta = {
+ homepage = "https://cryptpad.org";
+ mainProgram = "cryptpad-server";
+ };
+}