]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - pkgs/impure/etherpad-lite/default.nix
Move etherpad-lite to pkgs
[perso/Immae/Config/Nix.git] / pkgs / impure / etherpad-lite / default.nix
diff --git a/pkgs/impure/etherpad-lite/default.nix b/pkgs/impure/etherpad-lite/default.nix
new file mode 100644 (file)
index 0000000..c85bd7e
--- /dev/null
@@ -0,0 +1,69 @@
+{ session_key ? "/etc/etherpad-lite/SESSIONKEY.txt"
+, api_key ? "/etc/etherpad-lite/APIKEY.txt"
+, stdenv, mylibs, cacert, nodejs, python, fetchurl }:
+let
+  jquery = fetchurl {
+    url = https://code.jquery.com/jquery-1.9.1.js;
+    sha256 = "0h4dk67yc9d0kadqxb6b33585f3x3559p6qmp70l00qwq030vn3v";
+  };
+  withModules = modules: package.overrideAttrs(old: {
+    buildPhase = old.buildPhase +
+      builtins.concatStringsSep "\n"
+        (map (n: "npm install ${n}; touch node_modules/${n}/.ep_initialized") modules);
+    # FIXME: ln -s don’t seem to work, etherpad seems
+    # unable to "touch" them after initialization
+    passthru = old.passthru // {
+      inherit modules;
+      withModules = moreModules: old.withModules (moreModules ++ modules);
+    };
+  });
+  package = stdenv.mkDerivation (mylibs.fetchedGithub ./etherpad-lite.json // rec {
+    __noChroot = true;
+    patches = [ ./libreoffice_patch.diff ];
+    buildPhase = ''
+      export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
+      export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
+      export HOME=$PWD
+
+      touch src/.ep_initialized
+      cp -v src/static/custom/js.template src/static/custom/index.js
+      cp -v src/static/custom/js.template src/static/custom/pad.js
+      cp -v src/static/custom/js.template src/static/custom/timeslider.js
+      cp -v src/static/custom/css.template src/static/custom/index.css
+      cp -v src/static/custom/css.template src/static/custom/pad.css
+      cp -v src/static/custom/css.template src/static/custom/timeslider.css
+
+      sed -i 's/var\/dirty.db/\/var\/lib\/etherpad-lite\/dirty.db/g' \
+        settings.json.template
+
+      mkdir -v node_modules
+      ln -s ../src node_modules/ep_etherpad-lite
+
+      node bin/doc/generate doc/index.md --format=html \
+        --template=doc/template.html > documentation.html
+
+      cd src
+      npm install
+      cd ..
+      '';
+    installPhase = ''
+      mkdir -p $out
+      install -t $out/src/ -vDm 644 src/.ep_initialized
+      cp -a node_modules $out/
+      cp -a src/* $out/src/
+      ln -sf ${session_key} $out/SESSIONKEY.txt
+      ln -sf ${api_key} $out/APIKEY.txt
+      cp ${jquery} $out/src/static/js/jquery.js
+
+      mkdir $out/doc
+      install -t "$out/doc/" \
+        -vDm 644 {CHANGELOG,CONTRIBUTING,README}.md \
+        -vDm 644 documentation.html
+    '';
+    buildInputs = [ nodejs python ];
+    passthru = {
+      modules = [];
+      inherit withModules;
+    };
+  });
+in package