nixcfg/cluster/prod/app/cryptpad/build/default.nix

78 lines
2.5 KiB
Nix
Raw Normal View History

2022-05-06 15:34:30 +00:00
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")
];
});
});
npm = import ./nix.lock/npm.nix {
inherit pkgs;
};
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)
2022-05-06 15:55:23 +00:00
# Remove only office that IS BIG
2022-05-10 13:17:55 +00:00
# COMMENTED as it is not as easy as planned.
# rm -rf www/common/onlyoffice
2022-05-06 15:34:30 +00:00
'';
installPhase = ''
mkdir -p $out/{bin,opt}
2022-05-10 13:17:55 +00:00
out_cryptpad=$out/opt/
2022-05-06 15:34:30 +00:00
# copy the source code
2022-05-10 13:17:55 +00:00
cp -r .bowerrc bower.json package.json package-lock.json customize.dist lib server.js www $out_cryptpad
2022-05-06 15:34:30 +00:00
# mount node_modules
2022-05-10 13:17:55 +00:00
cp -r node_modules $out_cryptpad/node_modules
2022-05-06 15:34:30 +00:00
2022-05-10 13:17:55 +00:00
# patch
substituteInPlace $out_cryptpad/lib/workers/index.js --replace "lib/workers/db-worker" "$out_cryptpad/lib/workers/db-worker"
2022-05-06 15:34:30 +00:00
# mount bower, based on the .bowerrc file at the git repo root
2022-05-10 13:17:55 +00:00
cp -r ${bower}/bower_components $out_cryptpad/www/
2022-05-06 15:34:30 +00:00
# cryptpad is bugged with absolute path, this is a workaround to use absolute path as relative path
2022-05-10 13:17:55 +00:00
ln -s / $out_cryptpad/root
2022-05-06 15:34:30 +00:00
2022-05-10 13:17:55 +00:00
# start script, cryptpad is lost if its working directory is not its source directory
2022-05-06 15:34:30 +00:00
cat > $out/bin/cryptpad <<EOF
#!${pkgs.stdenv.shell}
2022-05-10 13:17:55 +00:00
cd $out_cryptpad
exec ${nodejs}/bin/node server.js
2022-05-06 15:34:30 +00:00
EOF
chmod +x $out/bin/cryptpad
'';
dontFixup = true;
}