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 (_) { } diff --git a/packages/projects.nix b/packages/projects.nix index 573b949..40e16e5 100644 --- a/packages/projects.nix +++ b/packages/projects.nix @@ -29,6 +29,19 @@ in in lib.recursiveUpdate ghost { meta.platforms = [ "x86_64-linux" ]; }; + uptime-kuma = let + dream = dream2nix.makeFlakeOutputs { + source = builtins.fetchTree { + type = "github"; + owner = "louislam"; + repo = "uptime-kuma"; + rev = "751924b3355ca44d24ceede1cfdd983383426f5f"; # 1.15.0 + }; + }; + inherit (dream.packages.${system}) uptime-kuma; + in + lib.recursiveUpdate uptime-kuma { meta.platforms = [ "x86_64-linux" ]; }; + hyprspace = pkgs.callPackage ./networking/hyprspace { iproute2mac = null; }; minio-console = pkgs.callPackage ./servers/minio-console { };