From f7f961dde81e0f56b31a314a53ddf072c6a9dd7a Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 27 Apr 2022 21:00:56 +0200 Subject: [PATCH] packages/uptime-kuma: add overrides and patches --- .../dream2nix-overrides/nodejs/default.nix | 39 +++++++++++++++++++ .../nodejs/uptime-kuma/chmod-database.patch | 12 ++++++ .../data-dir-concat-with-slash.patch | 30 ++++++++++++++ .../nodejs/uptime-kuma/log-in-data-dir.patch | 13 +++++++ 4 files changed, 94 insertions(+) create mode 100644 packages/dream2nix-overrides/nodejs/uptime-kuma/chmod-database.patch create mode 100644 packages/dream2nix-overrides/nodejs/uptime-kuma/data-dir-concat-with-slash.patch create mode 100644 packages/dream2nix-overrides/nodejs/uptime-kuma/log-in-data-dir.patch diff --git a/packages/dream2nix-overrides/nodejs/default.nix b/packages/dream2nix-overrides/nodejs/default.nix index 89cdda3..0f6b0d4 100644 --- a/packages/dream2nix-overrides/nodejs/default.nix +++ b/packages/dream2nix-overrides/nodejs/default.nix @@ -54,4 +54,43 @@ in --set NODE_PATH "$out/lib/node_modules/ghost/node_modules" ''; }; + + puppeteer.dummy-build = { + # HACK: doesn't build, but we don't need it anywhere + configurePhase = "exit 0"; + }; + + uptime-kuma.runtime-bugfixes = { + patches = [ + ./uptime-kuma/log-in-data-dir.patch + ./uptime-kuma/chmod-database.patch + ./uptime-kuma/data-dir-concat-with-slash.patch + ]; + }; + + uptime-kuma.build = { + # HACK: rollup.js is garbage and expects the contents of node_modules to not be symlinks + # obey its wishes by copying dependencies into place + preBuild = '' + cp -r node_modules $NIX_BUILD_TOP/node_modules_saved + find node_modules node_modules/@* -maxdepth 1 -type l -exec \ + bash -c 'LOC=$(readlink -f {}); echo unsymlinking: {}; rm {}; cp -r $LOC {}' \; + + chmod +w -R node_modules + find node_modules -mindepth 2 -name node_modules | xargs rm -rf + ''; + + preInstall = '' + echo restoring original node_modules directory + rm -rf node_modules + mv $NIX_BUILD_TOP/node_modules_saved node_modules + ''; + + postInstall = '' + makeWrapper $(command -v node) $out/bin/uptime-kuma \ + --add-flags "server/server.js" \ + --run "cd $out/lib/node_modules/uptime-kuma" \ + --set NODE_PATH "$out/lib/node_modules/uptime-kuma/node_modules" + ''; + }; } diff --git a/packages/dream2nix-overrides/nodejs/uptime-kuma/chmod-database.patch b/packages/dream2nix-overrides/nodejs/uptime-kuma/chmod-database.patch new file mode 100644 index 0000000..9c3f39c --- /dev/null +++ b/packages/dream2nix-overrides/nodejs/uptime-kuma/chmod-database.patch @@ -0,0 +1,12 @@ +diff --git a/server/server.js b/server/server.js +index 73ea3f5..31b8028 100644 +--- a/server/server.js ++++ b/server/server.js +@@ -1541,6 +1541,7 @@ async function initDatabase(testMode = false) { + if (! fs.existsSync(Database.path)) { + log.info("server", "Copying Database"); + fs.copyFileSync(Database.templatePath, Database.path); ++ fs.chmodSync(Database.path, 0o600); + } + + log.info("server", "Connecting to the Database"); diff --git a/packages/dream2nix-overrides/nodejs/uptime-kuma/data-dir-concat-with-slash.patch b/packages/dream2nix-overrides/nodejs/uptime-kuma/data-dir-concat-with-slash.patch new file mode 100644 index 0000000..15f7459 --- /dev/null +++ b/packages/dream2nix-overrides/nodejs/uptime-kuma/data-dir-concat-with-slash.patch @@ -0,0 +1,30 @@ +diff --git a/server/database.js b/server/database.js +index b17e7f4..7b77f84 100644 +--- a/server/database.js ++++ b/server/database.js +@@ -74,13 +74,13 @@ class Database { + */ + static init(args) { + // Data Directory (must be end with "/") +- Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data/"; +- Database.path = Database.dataDir + "kuma.db"; ++ Database.dataDir = process.env.DATA_DIR || args["data-dir"] || "./data"; ++ Database.path = Database.dataDir + "/kuma.db"; + if (! fs.existsSync(Database.dataDir)) { + fs.mkdirSync(Database.dataDir, { recursive: true }); + } + +- Database.uploadDir = Database.dataDir + "upload/"; ++ Database.uploadDir = Database.dataDir + "/upload/"; + + if (! fs.existsSync(Database.uploadDir)) { + fs.mkdirSync(Database.uploadDir, { recursive: true }); +@@ -429,7 +429,7 @@ class Database { + static backup(version) { + if (! this.backupPath) { + log.info("db", "Backing up the database"); +- this.backupPath = this.dataDir + "kuma.db.bak" + version; ++ this.backupPath = this.dataDir + "/kuma.db.bak" + version; + fs.copyFileSync(Database.path, this.backupPath); + + const shmPath = Database.path + "-shm"; diff --git a/packages/dream2nix-overrides/nodejs/uptime-kuma/log-in-data-dir.patch b/packages/dream2nix-overrides/nodejs/uptime-kuma/log-in-data-dir.patch new file mode 100644 index 0000000..88cfd5d --- /dev/null +++ b/packages/dream2nix-overrides/nodejs/uptime-kuma/log-in-data-dir.patch @@ -0,0 +1,13 @@ +diff --git a/server/util-server.js b/server/util-server.js +index 39a2d90..ecb404a 100644 +--- a/server/util-server.js ++++ b/server/util-server.js +@@ -528,7 +528,7 @@ exports.convertToUTF8 = (body) => { + let logFile; + + try { +- logFile = fs.createWriteStream("./data/error.log", { ++ logFile = fs.createWriteStream((process.env.DATA_DIR || ".") + "/error.log", { + flags: "a" + }); + } catch (_) { }