From 47650011443d71f7c9c2823f2ab49edc12b54d41 Mon Sep 17 00:00:00 2001 From: matt1432 <matt@nelim.org> Date: Fri, 14 Mar 2025 19:36:59 -0400 Subject: [PATCH] feat: attempt to update homepage to 1.0.0 --- packages/homepage/default.nix | 79 +++++++++++--------- packages/homepage/prerender_cache_path.patch | 18 ----- packages/homepage/update.sh | 15 ++++ 3 files changed, 58 insertions(+), 54 deletions(-) delete mode 100644 packages/homepage/prerender_cache_path.patch create mode 100644 packages/homepage/update.sh diff --git a/packages/homepage/default.nix b/packages/homepage/default.nix index a277a7fb..ced7e056 100644 --- a/packages/homepage/default.nix +++ b/packages/homepage/default.nix @@ -4,36 +4,40 @@ # nix build inputs lib, stdenv, - buildNpmPackage, + concatTextFile, fetchFromGitHub, + makeWrapper, # deps - cctools, git, - nodePackages, + nodejs, + pnpm, python3, - IOKit ? {}, + ... }: let - inherit (lib) optionals optionalString; + inherit (lib) optionalString; installLocalIcons = import ./icons.nix {inherit fetchFromGitHub;}; - - pname = "homepage-dashboard"; - version = "0.10.9"; in - buildNpmPackage { - inherit pname version; + stdenv.mkDerivation (finalAttrs: { + pname = "homepage-dashboard"; + version = "1.0.0"; src = fetchFromGitHub { owner = "gethomepage"; repo = "homepage"; - rev = "v${version}"; - hash = "sha256-q8+uoikHMQVuTrVSH8tPsoI5655ZStMc/7tmoAfoZIY="; + rev = "v${finalAttrs.version}"; + hash = "sha256-j543lwSWOFuPjHCTN/4vEKME39RpG4D16qWeSrL5hZY="; }; - npmDepsHash = "sha256-N39gwct2U4UxlIL5ceDzzU7HpA6xh2WksrZNxGz04PU="; + pnpmDepsHash = "sha256-E16+JLtfoiWCXwgFGdTGuFlx/pYxhINNl6tCuF9Z6MQ="; - preBuild = '' - mkdir -p config + pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) pname version src; + hash = finalAttrs.pnpmDepsHash; + }; + + buildPhase = '' + pnpm build ''; postBuild = '' @@ -42,13 +46,12 @@ in patchShebangs .next/standalone/server.js ''; - nativeBuildInputs = [git] ++ optionals stdenv.hostPlatform.isDarwin [cctools]; - - buildInputs = - [ - nodePackages.node-gyp-build - ] - ++ optionals stdenv.hostPlatform.isDarwin [IOKit]; + nativeBuildInputs = [ + git + makeWrapper + nodejs + pnpm.configHook + ]; env.PYTHON = "${python3}/bin/python"; @@ -57,6 +60,16 @@ in mkdir -p $out/{share,bin} + # Without this, homepage-dashboard errors when trying to + # write its prerender cache. + # + # This ensures that the cache implementation respects the env + # variable `HOMEPAGE_CACHE_DIR`, which is set by default in the + # wrapper below. + substituteInPlace .next/standalone/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js --replace-fail \ + "this.serverDistDir = ctx.serverDistDir;" \ + "this.serverDistDir = require('node:path').join(process.env.HOMEPAGE_CACHE_DIR, \"homepage\");" + cp -r .next/standalone $out/share/homepage/ cp -r public $out/share/homepage/public @@ -65,17 +78,6 @@ in chmod +x $out/share/homepage/server.js - # This patch must be applied here, as it's patching the `dist` directory - # of NextJS. Without this, homepage-dashboard errors when trying to - # write its prerender cache. - # - # This patch ensures that the cache implementation respects the env - # variable `HOMEPAGE_CACHE_DIR`, which is set by default in the - # wrapper below. - pushd $out - git apply ${./prerender_cache_path.patch} - popd - makeWrapper $out/share/homepage/server.js $out/bin/homepage \ --set-default PORT 3000 \ --set-default HOMEPAGE_CONFIG_DIR /var/lib/homepage-dashboard \ @@ -86,15 +88,20 @@ in runHook postInstall ''; - doDist = false; + passthru.updateScript = concatTextFile { + name = "update"; + files = [./update.sh]; + executable = true; + destination = "/bin/update"; + }; meta = { mainProgram = "homepage"; license = lib.licenses.gpl3; homepage = "https://gethomepage.dev"; - changelog = "https://github.com/gethomepage/homepage/releases/tag/v${version}"; + changelog = "https://github.com/gethomepage/homepage/releases/tag/v${finalAttrs.version}"; description = '' Highly customisable dashboard with Docker and service API integrations. ''; }; - } + }) diff --git a/packages/homepage/prerender_cache_path.patch b/packages/homepage/prerender_cache_path.patch deleted file mode 100644 index 05746b56..00000000 --- a/packages/homepage/prerender_cache_path.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/share/homepage/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js b/share/homepage/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js -index b1b74d8..a46c80b 100644 ---- a/share/homepage/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js -+++ b/share/homepage/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js -@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", { - exports.default = void 0; - var _lruCache = _interopRequireDefault(require("next/dist/compiled/lru-cache")); - var _path = _interopRequireDefault(require("../../../shared/lib/isomorphic/path")); -+var path = require('node:path'); - class FileSystemCache { - constructor(ctx){ - this.fs = ctx.fs; - this.flushToDisk = ctx.flushToDisk; -- this.serverDistDir = ctx.serverDistDir; -+ this.serverDistDir = path.join(process.env.HOMEPAGE_CACHE_DIR, "homepage"); - this.appDir = !!ctx._appDir; - if (ctx.maxMemoryCacheSize) { - this.memoryCache = new _lruCache.default({ diff --git a/packages/homepage/update.sh b/packages/homepage/update.sh new file mode 100644 index 00000000..bb249883 --- /dev/null +++ b/packages/homepage/update.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +nix-update --flake homepage + +file="$FLAKE/packages/homepage/default.nix" +old_hash="$(sed -n 's/.*pnpmDepsHash = "\(.*\)";/\1/p' "$file")" + +sed -i "s/pnpmDepsHash = .*/pnpmDepsHash = \"\";/" "$file" +npm_hash="$(nix build "$FLAKE#homepage" |& sed -n 's/.*got: *//p')" + +if [[ "$npm_hash" != "$old_hash" ]]; then + sed -i "s#pnpmDepsHash = .*#pnpmDepsHash = \"$npm_hash\";#" "$file" +else + sed -i "s#pnpmDepsHash = .*#pnpmDepsHash = \"$old_hash\";#" "$file" +fi