aboutsummaryrefslogtreecommitdiff
path: root/app/cryptpad/build/default.nix
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2022-05-06 17:34:30 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2022-05-06 17:35:09 +0200
commit071e87a2025edfa8694fd3ae05be894d2be434ee (patch)
treecacc8e997f669a3ae497b2256394aa90c83c711e /app/cryptpad/build/default.nix
parent0561fa8d5f07f183a27b068feb820e4777b0c020 (diff)
downloadnixcfg-071e87a2025edfa8694fd3ae05be894d2be434ee.tar.gz
nixcfg-071e87a2025edfa8694fd3ae05be894d2be434ee.zip
Own packaging of Cryptpad
Diffstat (limited to 'app/cryptpad/build/default.nix')
-rw-r--r--app/cryptpad/build/default.nix69
1 files changed, 69 insertions, 0 deletions
diff --git a/app/cryptpad/build/default.nix b/app/cryptpad/build/default.nix
new file mode 100644
index 0000000..2cf0ae3
--- /dev/null
+++ b/app/cryptpad/build/default.nix
@@ -0,0 +1,69 @@
+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)
+ '';
+
+ installPhase = ''
+ mkdir -p $out/{bin,opt}
+
+ # copy the source code
+ cp -r customize.dist lib server.js www $out/opt/
+
+ # mount node_modules
+ cp -r node_modules $out/opt/node_modules
+
+
+ # mount bower, based on the .bowerrc file at the git repo root
+ cp -r ${bower} $out/opt/www/bower_components
+
+ # cryptpad is bugged with absolute path, this is a workaround to use absolute path as relative path
+ ln -s / $out/opt/root
+
+ # start script
+ cat > $out/bin/cryptpad <<EOF
+ #!${pkgs.stdenv.shell}
+ cd $out/opt/
+ ${nodejs}/bin/node server.js
+ EOF
+
+ chmod +x $out/bin/cryptpad
+ '';
+
+ dontFixup = true;
+ }