Loading nixos/modules/services/misc/homepage-dashboard.nix +41 −71 Original line number Diff line number Diff line Loading @@ -192,38 +192,10 @@ in }; }; config = let # If homepage-dashboard is enabled, but none of the configuration values have been updated, # then default to "unmanaged" configuration which is manually updated in # var/lib/homepage-dashboard. This is to maintain backwards compatibility, and should be # deprecated in a future release. managedConfig = !( cfg.bookmarks == [ ] && cfg.customCSS == "" && cfg.customJS == "" && cfg.docker == { } && cfg.kubernetes == { } && cfg.services == [ ] && cfg.settings == { } && cfg.widgets == [ ] ); configDir = if managedConfig then "/etc/homepage-dashboard" else "/var/lib/homepage-dashboard"; msg = "using unmanaged configuration for homepage-dashboard is deprecated and will be removed" + " in 24.05. please see the NixOS documentation for `services.homepage-dashboard' and add" + " your bookmarks, services, widgets, and other configuration using the options provided."; in lib.mkIf cfg.enable { warnings = lib.optional (!managedConfig) msg; environment.etc = lib.mkIf managedConfig { config = lib.mkIf cfg.enable { environment.etc = { "homepage-dashboard/custom.css".text = cfg.customCSS; "homepage-dashboard/custom.js".text = cfg.customJS; "homepage-dashboard/bookmarks.yaml".source = settingsFormat.generate "bookmarks.yaml" cfg.bookmarks; "homepage-dashboard/docker.yaml".source = settingsFormat.generate "docker.yaml" cfg.docker; "homepage-dashboard/kubernetes.yaml".source = Loading @@ -239,30 +211,28 @@ in wantedBy = [ "multi-user.target" ]; environment = { HOMEPAGE_CONFIG_DIR = configDir; HOMEPAGE_CONFIG_DIR = "/etc/homepage-dashboard"; NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard"; PORT = toString cfg.listenPort; LOG_TARGETS = lib.mkIf managedConfig "stdout"; LOG_TARGETS = "stdout"; }; serviceConfig = { Type = "simple"; DynamicUser = true; EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; StateDirectory = lib.mkIf (!managedConfig) "homepage-dashboard"; StateDirectory = "homepage-dashboard"; CacheDirectory = "homepage-dashboard"; ExecStart = lib.getExe cfg.package; Restart = "on-failure"; }; enableStrictShellChecks = true; preStart = '' # Related: # * https://github.com/NixOS/nixpkgs/issues/346016 ("homepage-dashboard: cache dir is not cleared upon version upgrade") # * https://github.com/gethomepage/homepage/discussions/4560 ("homepage NixOS package does not clear cache on upgrade leaving broken state") # * https://github.com/vercel/next.js/discussions/58864 ("Feature Request: Allow configuration of cache dir") rm -rf "''${NIXPKGS_HOMEPAGE_CACHE_DIR:?}"/* preStart = '' rm -rf "$NIXPKGS_HOMEPAGE_CACHE_DIR"/* ''; }; Loading nixos/tests/homepage-dashboard.nix +11 −32 Original line number Diff line number Diff line Loading @@ -4,15 +4,7 @@ import ./make-test-python.nix ( name = "homepage-dashboard"; meta.maintainers = with lib.maintainers; [ jnsgruk ]; nodes.unmanaged_conf = { pkgs, ... }: { services.homepage-dashboard.enable = true; }; nodes.managed_conf = { pkgs, ... }: { nodes.machine = _: { services.homepage-dashboard = { enable = true; settings.title = "test title rodUsEagid"; # something random/unique Loading @@ -20,30 +12,17 @@ import ./make-test-python.nix ( }; testScript = '' # Ensure the services are started on unmanaged machine unmanaged_conf.wait_for_unit("homepage-dashboard.service") unmanaged_conf.wait_for_open_port(8082) unmanaged_conf.succeed("curl --fail http://localhost:8082/") # Ensure that /etc/homepage-dashboard doesn't exist, and boilerplate # configs are copied into place. unmanaged_conf.fail("test -d /etc/homepage-dashboard") unmanaged_conf.succeed("test -f /var/lib/private/homepage-dashboard/settings.yaml") # Ensure the services are started on managed machine managed_conf.wait_for_unit("homepage-dashboard.service") managed_conf.wait_for_open_port(8082) managed_conf.succeed("curl --fail http://localhost:8082/") machine.wait_for_unit("homepage-dashboard.service") machine.wait_for_open_port(8082) machine.succeed("curl --fail http://localhost:8082/") # Ensure /etc/homepage-dashboard is created and unmanaged conf location isn't. managed_conf.succeed("test -d /etc/homepage-dashboard") managed_conf.fail("test -f /var/lib/private/homepage-dashboard/settings.yaml") # Ensure /etc/homepage-dashboard is created. machine.succeed("test -d /etc/homepage-dashboard") # Ensure that we see the custom title *only in the managed config* page = managed_conf.succeed("curl --fail http://localhost:8082/") page = machine.succeed("curl --fail http://localhost:8082/") assert "test title rodUsEagid" in page, "Custom title not found" page = unmanaged_conf.succeed("curl --fail http://localhost:8082/") assert "test title rodUsEagid" not in page, "Custom title found where it shouldn't be" ''; } ) pkgs/servers/homepage-dashboard/default.nix→pkgs/by-name/ho/homepage-dashboard/package.nix +44 −38 Original line number Diff line number Diff line { buildNpmPackage, fetchFromGitHub, nodePackages, makeBinaryWrapper, nodejs, pnpm_10, python3, stdenv, cctools, IOKit, darwin, lib, nixosTests, enableLocalIcons ? false, nix-update-script, }: let dashboardIcons = fetchFromGitHub { Loading @@ -26,63 +27,68 @@ let cp ${dashboardIcons}/LICENSE $out/share/homepage/public/icons/ ''; in buildNpmPackage rec { stdenv.mkDerivation (finalAttrs: { pname = "homepage-dashboard"; version = "0.10.9"; version = "1.0.4"; src = fetchFromGitHub { owner = "gethomepage"; repo = "homepage"; rev = "v${version}"; hash = "sha256-q8+uoikHMQVuTrVSH8tPsoI5655ZStMc/7tmoAfoZIY="; tag = "v${finalAttrs.version}"; hash = "sha256-SwzgmVy3TBzEH+FJ/kY+iCo+pZhud1IZkfCh2DiSTsk="; }; npmDepsHash = "sha256-N39gwct2U4UxlIL5ceDzzU7HpA6xh2WksrZNxGz04PU="; preBuild = '' mkdir -p config ''; postBuild = '' # Add a shebang to the server js file, then patch the shebang. sed -i '1s|^|#!/usr/bin/env node\n|' .next/standalone/server.js patchShebangs .next/standalone/server.js ''; # This patch ensures that the cache implementation respects the env # variable `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the # wrapper below. # The patch is automatically generated by the `update.sh` script. patches = [ ./prerender_cache_path.patch ]; pnpmDeps = pnpm_10.fetchDeps { inherit (finalAttrs) pname version src patches ; hash = "sha256-GUDSfAbBK+6Bbih5jBrkjiMYLOJM7gMfurXFeez1bSw="; }; nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; nativeBuildInputs = [ makeBinaryWrapper nodejs pnpm_10.configHook ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; buildInputs = [ nodePackages.node-gyp-build ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ IOKit ]; ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.IOKit ]; env.PYTHON = "${python3}/bin/python"; buildPhase = '' runHook preBuild mkdir -p config pnpm build runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out/{share,bin} mkdir -p $out/{bin,share} cp -r .next/standalone $out/share/homepage/ cp -r public $out/share/homepage/public chmod +x $out/share/homepage/server.js mkdir -p $out/share/homepage/.next cp -r .next/static $out/share/homepage/.next/static 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 `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the # wrapper below. (cd "$out" && patch -p1 <${./prerender_cache_path.patch}) makeWrapper $out/share/homepage/server.js $out/bin/homepage \ makeWrapper "${lib.getExe nodejs}" $out/bin/homepage \ --set-default PORT 3000 \ --set-default HOMEPAGE_CONFIG_DIR /var/lib/homepage-dashboard \ --set-default NIXPKGS_HOMEPAGE_CACHE_DIR /var/cache/homepage-dashboard --set-default NIXPKGS_HOMEPAGE_CACHE_DIR /var/cache/homepage-dashboard \ --add-flags "$out/share/homepage/server.js" ${if enableLocalIcons then installLocalIcons else ""} Loading @@ -95,12 +101,12 @@ buildNpmPackage rec { tests = { inherit (nixosTests) homepage-dashboard; }; updateScript = nix-update-script { }; updateScript = ./update.sh; }; meta = { description = "Highly customisable dashboard with Docker and service API integrations"; changelog = "https://github.com/gethomepage/homepage/releases/tag/v${version}"; changelog = "https://github.com/gethomepage/homepage/releases/tag/v${finalAttrs.version}"; mainProgram = "homepage"; homepage = "https://gethomepage.dev"; license = lib.licenses.gpl3; Loading @@ -108,4 +114,4 @@ buildNpmPackage rec { platforms = lib.platforms.all; broken = stdenv.hostPlatform.isDarwin; }; } }) pkgs/by-name/ho/homepage-dashboard/prerender_cache_path.patch 0 → 100644 +89 −0 Original line number Diff line number Diff line diff --git c/package.json i/package.json index 44fc1b35..4164abf3 100644 --- c/package.json +++ i/package.json @@ -62,5 +62,10 @@ }, "optionalDependencies": { "osx-temperature-sensor": "^1.0.8" + }, + "pnpm": { + "patchedDependencies": { + "next": "patches/next.patch" + } } } diff --git c/patches/next.patch i/patches/next.patch new file mode 100644 index 00000000..6280dbfa --- /dev/null +++ i/patches/next.patch @@ -0,0 +1,13 @@ +diff --git a/dist/server/lib/incremental-cache/file-system-cache.js b/dist/server/lib/incremental-cache/file-system-cache.js +index ac711f168d85032d43cfa2b6872655d571596a7b..ee1f79868d38ae623b0599e8cc3b9e03697833e5 100644 +--- a/dist/server/lib/incremental-cache/file-system-cache.js ++++ b/dist/server/lib/incremental-cache/file-system-cache.js +@@ -23,7 +23,7 @@ class FileSystemCache { + constructor(ctx){ + this.fs = ctx.fs; + this.flushToDisk = ctx.flushToDisk; +- this.serverDistDir = ctx.serverDistDir; ++ this.serverDistDir = require("path").join((process.env.NIXPKGS_HOMEPAGE_CACHE_DIR || "/var/cache/homepage-dashboard"), "homepage"); + this.revalidatedTags = ctx.revalidatedTags; + this.debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE; + if (ctx.maxMemoryCacheSize) { diff --git c/pnpm-lock.yaml i/pnpm-lock.yaml index 6b5c5910..84712cd2 100644 --- c/pnpm-lock.yaml +++ i/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +patchedDependencies: + next: + hash: 2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49 + path: patches/next.patch + importers: .: @@ -52,10 +57,10 @@ importers: version: 1.2.2 next: specifier: ^15.1.7 - version: 15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + version: 15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) next-i18next: specifier: ^12.1.0 - version: 12.1.0(next@15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + version: 12.1.0(next@15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) ping: specifier: ^0.4.4 version: 0.4.4 @@ -4688,7 +4693,7 @@ snapshots: natural-compare@1.4.0: {} - next-i18next@12.1.0(next@15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + next-i18next@12.1.0(next@15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: '@babel/runtime': 7.26.9 '@types/hoist-non-react-statics': 3.3.6 @@ -4696,14 +4701,14 @@ snapshots: hoist-non-react-statics: 3.3.2 i18next: 21.10.0 i18next-fs-backend: 1.2.0 - next: 15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + next: 15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) react: 18.3.1 react-i18next: 11.18.6(i18next@21.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) transitivePeerDependencies: - react-dom - react-native - next@15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + next@15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: '@next/env': 15.1.7 '@swc/counter': 0.1.3 pkgs/by-name/ho/homepage-dashboard/update.sh 0 → 100755 +66 −0 Original line number Diff line number Diff line #!/usr/bin/env nix-shell #!nix-shell -I nixpkgs=./. -i bash -p curl jq git pnpm_10 sd # shellcheck shell=bash set -euo pipefail nixpkgs="$(pwd)" cd $(readlink -e $(dirname "${BASH_SOURCE[0]}")) # Generate the patch file that makes homepage-dashboard aware of the NIXPKGS_HOMEPAGE_CACHE_DIR environment variable. # Generating the patch this way ensures that both the patch is included, and the lock file is updated. generate_patch() { local version; version="$1" echo "Generating homepage-dashboard patch" git clone -b "v$version" https://github.com/gethomepage/homepage.git src pushd src pnpm install pnpm patch next sd \ 'this.serverDistDir = ctx.serverDistDir;' \ 'this.serverDistDir = require("path").join((process.env.NIXPKGS_HOMEPAGE_CACHE_DIR || "/var/cache/homepage-dashboard"), "homepage");' \ node_modules/.pnpm_patches/next*/dist/server/lib/incremental-cache/file-system-cache.js pnpm patch-commit node_modules/.pnpm_patches/next* git add -A . git diff -p --staged > ../prerender_cache_path.patch popd rm -rf src } # Update the hash of the homepage-dashboard source code in the Nix expression. update_homepage_dashboard_source() { local version; version="$1" echo "Updating homepage-dashboard source" old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.src.outputHash" | jq -r)" old_version="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.version" | jq -r)" new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).homepage-dashboard.src; in (src.overrideAttrs or (f: src // f src)) (_: { version = \"$version\"; outputHash = \"\"; outputHashAlgo = \"sha256\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true sed -i "s|${old_hash}|${new_hash}|g" package.nix sed -i "s|${old_version}|${version}|g" package.nix } # Update the hash of the homepage-dashboard pnpm dependencies in the Nix expression. update_pnpm_deps_hash() { echo "Updating homepage-dashboard pnpm deps hash" old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.pnpmDeps.outputHash" | jq -r)" new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).homepage-dashboard.pnpmDeps; in (src.overrideAttrs or (f: src // f src)) (_: { outputHash = \"\"; outputHashAlgo = \"sha256\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true sed -i "s|${old_hash}|${new_hash}|g" package.nix } LATEST_TAG="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/gethomepage/homepage/releases/latest | jq -r '.tag_name')" LATEST_VERSION="$(expr "$LATEST_TAG" : 'v\(.*\)')" CURRENT_VERSION="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.version" | jq -r)" if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then echo "homepage-dashboard is up to date: ${CURRENT_VERSION}" exit 0 fi update_homepage_dashboard_source "$LATEST_VERSION" generate_patch "$LATEST_VERSION" update_pnpm_deps_hash Loading
nixos/modules/services/misc/homepage-dashboard.nix +41 −71 Original line number Diff line number Diff line Loading @@ -192,38 +192,10 @@ in }; }; config = let # If homepage-dashboard is enabled, but none of the configuration values have been updated, # then default to "unmanaged" configuration which is manually updated in # var/lib/homepage-dashboard. This is to maintain backwards compatibility, and should be # deprecated in a future release. managedConfig = !( cfg.bookmarks == [ ] && cfg.customCSS == "" && cfg.customJS == "" && cfg.docker == { } && cfg.kubernetes == { } && cfg.services == [ ] && cfg.settings == { } && cfg.widgets == [ ] ); configDir = if managedConfig then "/etc/homepage-dashboard" else "/var/lib/homepage-dashboard"; msg = "using unmanaged configuration for homepage-dashboard is deprecated and will be removed" + " in 24.05. please see the NixOS documentation for `services.homepage-dashboard' and add" + " your bookmarks, services, widgets, and other configuration using the options provided."; in lib.mkIf cfg.enable { warnings = lib.optional (!managedConfig) msg; environment.etc = lib.mkIf managedConfig { config = lib.mkIf cfg.enable { environment.etc = { "homepage-dashboard/custom.css".text = cfg.customCSS; "homepage-dashboard/custom.js".text = cfg.customJS; "homepage-dashboard/bookmarks.yaml".source = settingsFormat.generate "bookmarks.yaml" cfg.bookmarks; "homepage-dashboard/docker.yaml".source = settingsFormat.generate "docker.yaml" cfg.docker; "homepage-dashboard/kubernetes.yaml".source = Loading @@ -239,30 +211,28 @@ in wantedBy = [ "multi-user.target" ]; environment = { HOMEPAGE_CONFIG_DIR = configDir; HOMEPAGE_CONFIG_DIR = "/etc/homepage-dashboard"; NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard"; PORT = toString cfg.listenPort; LOG_TARGETS = lib.mkIf managedConfig "stdout"; LOG_TARGETS = "stdout"; }; serviceConfig = { Type = "simple"; DynamicUser = true; EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; StateDirectory = lib.mkIf (!managedConfig) "homepage-dashboard"; StateDirectory = "homepage-dashboard"; CacheDirectory = "homepage-dashboard"; ExecStart = lib.getExe cfg.package; Restart = "on-failure"; }; enableStrictShellChecks = true; preStart = '' # Related: # * https://github.com/NixOS/nixpkgs/issues/346016 ("homepage-dashboard: cache dir is not cleared upon version upgrade") # * https://github.com/gethomepage/homepage/discussions/4560 ("homepage NixOS package does not clear cache on upgrade leaving broken state") # * https://github.com/vercel/next.js/discussions/58864 ("Feature Request: Allow configuration of cache dir") rm -rf "''${NIXPKGS_HOMEPAGE_CACHE_DIR:?}"/* preStart = '' rm -rf "$NIXPKGS_HOMEPAGE_CACHE_DIR"/* ''; }; Loading
nixos/tests/homepage-dashboard.nix +11 −32 Original line number Diff line number Diff line Loading @@ -4,15 +4,7 @@ import ./make-test-python.nix ( name = "homepage-dashboard"; meta.maintainers = with lib.maintainers; [ jnsgruk ]; nodes.unmanaged_conf = { pkgs, ... }: { services.homepage-dashboard.enable = true; }; nodes.managed_conf = { pkgs, ... }: { nodes.machine = _: { services.homepage-dashboard = { enable = true; settings.title = "test title rodUsEagid"; # something random/unique Loading @@ -20,30 +12,17 @@ import ./make-test-python.nix ( }; testScript = '' # Ensure the services are started on unmanaged machine unmanaged_conf.wait_for_unit("homepage-dashboard.service") unmanaged_conf.wait_for_open_port(8082) unmanaged_conf.succeed("curl --fail http://localhost:8082/") # Ensure that /etc/homepage-dashboard doesn't exist, and boilerplate # configs are copied into place. unmanaged_conf.fail("test -d /etc/homepage-dashboard") unmanaged_conf.succeed("test -f /var/lib/private/homepage-dashboard/settings.yaml") # Ensure the services are started on managed machine managed_conf.wait_for_unit("homepage-dashboard.service") managed_conf.wait_for_open_port(8082) managed_conf.succeed("curl --fail http://localhost:8082/") machine.wait_for_unit("homepage-dashboard.service") machine.wait_for_open_port(8082) machine.succeed("curl --fail http://localhost:8082/") # Ensure /etc/homepage-dashboard is created and unmanaged conf location isn't. managed_conf.succeed("test -d /etc/homepage-dashboard") managed_conf.fail("test -f /var/lib/private/homepage-dashboard/settings.yaml") # Ensure /etc/homepage-dashboard is created. machine.succeed("test -d /etc/homepage-dashboard") # Ensure that we see the custom title *only in the managed config* page = managed_conf.succeed("curl --fail http://localhost:8082/") page = machine.succeed("curl --fail http://localhost:8082/") assert "test title rodUsEagid" in page, "Custom title not found" page = unmanaged_conf.succeed("curl --fail http://localhost:8082/") assert "test title rodUsEagid" not in page, "Custom title found where it shouldn't be" ''; } )
pkgs/servers/homepage-dashboard/default.nix→pkgs/by-name/ho/homepage-dashboard/package.nix +44 −38 Original line number Diff line number Diff line { buildNpmPackage, fetchFromGitHub, nodePackages, makeBinaryWrapper, nodejs, pnpm_10, python3, stdenv, cctools, IOKit, darwin, lib, nixosTests, enableLocalIcons ? false, nix-update-script, }: let dashboardIcons = fetchFromGitHub { Loading @@ -26,63 +27,68 @@ let cp ${dashboardIcons}/LICENSE $out/share/homepage/public/icons/ ''; in buildNpmPackage rec { stdenv.mkDerivation (finalAttrs: { pname = "homepage-dashboard"; version = "0.10.9"; version = "1.0.4"; src = fetchFromGitHub { owner = "gethomepage"; repo = "homepage"; rev = "v${version}"; hash = "sha256-q8+uoikHMQVuTrVSH8tPsoI5655ZStMc/7tmoAfoZIY="; tag = "v${finalAttrs.version}"; hash = "sha256-SwzgmVy3TBzEH+FJ/kY+iCo+pZhud1IZkfCh2DiSTsk="; }; npmDepsHash = "sha256-N39gwct2U4UxlIL5ceDzzU7HpA6xh2WksrZNxGz04PU="; preBuild = '' mkdir -p config ''; postBuild = '' # Add a shebang to the server js file, then patch the shebang. sed -i '1s|^|#!/usr/bin/env node\n|' .next/standalone/server.js patchShebangs .next/standalone/server.js ''; # This patch ensures that the cache implementation respects the env # variable `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the # wrapper below. # The patch is automatically generated by the `update.sh` script. patches = [ ./prerender_cache_path.patch ]; pnpmDeps = pnpm_10.fetchDeps { inherit (finalAttrs) pname version src patches ; hash = "sha256-GUDSfAbBK+6Bbih5jBrkjiMYLOJM7gMfurXFeez1bSw="; }; nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; nativeBuildInputs = [ makeBinaryWrapper nodejs pnpm_10.configHook ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; buildInputs = [ nodePackages.node-gyp-build ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ IOKit ]; ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk.frameworks.IOKit ]; env.PYTHON = "${python3}/bin/python"; buildPhase = '' runHook preBuild mkdir -p config pnpm build runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out/{share,bin} mkdir -p $out/{bin,share} cp -r .next/standalone $out/share/homepage/ cp -r public $out/share/homepage/public chmod +x $out/share/homepage/server.js mkdir -p $out/share/homepage/.next cp -r .next/static $out/share/homepage/.next/static 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 `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the # wrapper below. (cd "$out" && patch -p1 <${./prerender_cache_path.patch}) makeWrapper $out/share/homepage/server.js $out/bin/homepage \ makeWrapper "${lib.getExe nodejs}" $out/bin/homepage \ --set-default PORT 3000 \ --set-default HOMEPAGE_CONFIG_DIR /var/lib/homepage-dashboard \ --set-default NIXPKGS_HOMEPAGE_CACHE_DIR /var/cache/homepage-dashboard --set-default NIXPKGS_HOMEPAGE_CACHE_DIR /var/cache/homepage-dashboard \ --add-flags "$out/share/homepage/server.js" ${if enableLocalIcons then installLocalIcons else ""} Loading @@ -95,12 +101,12 @@ buildNpmPackage rec { tests = { inherit (nixosTests) homepage-dashboard; }; updateScript = nix-update-script { }; updateScript = ./update.sh; }; meta = { description = "Highly customisable dashboard with Docker and service API integrations"; changelog = "https://github.com/gethomepage/homepage/releases/tag/v${version}"; changelog = "https://github.com/gethomepage/homepage/releases/tag/v${finalAttrs.version}"; mainProgram = "homepage"; homepage = "https://gethomepage.dev"; license = lib.licenses.gpl3; Loading @@ -108,4 +114,4 @@ buildNpmPackage rec { platforms = lib.platforms.all; broken = stdenv.hostPlatform.isDarwin; }; } })
pkgs/by-name/ho/homepage-dashboard/prerender_cache_path.patch 0 → 100644 +89 −0 Original line number Diff line number Diff line diff --git c/package.json i/package.json index 44fc1b35..4164abf3 100644 --- c/package.json +++ i/package.json @@ -62,5 +62,10 @@ }, "optionalDependencies": { "osx-temperature-sensor": "^1.0.8" + }, + "pnpm": { + "patchedDependencies": { + "next": "patches/next.patch" + } } } diff --git c/patches/next.patch i/patches/next.patch new file mode 100644 index 00000000..6280dbfa --- /dev/null +++ i/patches/next.patch @@ -0,0 +1,13 @@ +diff --git a/dist/server/lib/incremental-cache/file-system-cache.js b/dist/server/lib/incremental-cache/file-system-cache.js +index ac711f168d85032d43cfa2b6872655d571596a7b..ee1f79868d38ae623b0599e8cc3b9e03697833e5 100644 +--- a/dist/server/lib/incremental-cache/file-system-cache.js ++++ b/dist/server/lib/incremental-cache/file-system-cache.js +@@ -23,7 +23,7 @@ class FileSystemCache { + constructor(ctx){ + this.fs = ctx.fs; + this.flushToDisk = ctx.flushToDisk; +- this.serverDistDir = ctx.serverDistDir; ++ this.serverDistDir = require("path").join((process.env.NIXPKGS_HOMEPAGE_CACHE_DIR || "/var/cache/homepage-dashboard"), "homepage"); + this.revalidatedTags = ctx.revalidatedTags; + this.debug = !!process.env.NEXT_PRIVATE_DEBUG_CACHE; + if (ctx.maxMemoryCacheSize) { diff --git c/pnpm-lock.yaml i/pnpm-lock.yaml index 6b5c5910..84712cd2 100644 --- c/pnpm-lock.yaml +++ i/pnpm-lock.yaml @@ -4,6 +4,11 @@ settings: autoInstallPeers: true excludeLinksFromLockfile: false +patchedDependencies: + next: + hash: 2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49 + path: patches/next.patch + importers: .: @@ -52,10 +57,10 @@ importers: version: 1.2.2 next: specifier: ^15.1.7 - version: 15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + version: 15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) next-i18next: specifier: ^12.1.0 - version: 12.1.0(next@15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + version: 12.1.0(next@15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) ping: specifier: ^0.4.4 version: 0.4.4 @@ -4688,7 +4693,7 @@ snapshots: natural-compare@1.4.0: {} - next-i18next@12.1.0(next@15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + next-i18next@12.1.0(next@15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: '@babel/runtime': 7.26.9 '@types/hoist-non-react-statics': 3.3.6 @@ -4696,14 +4701,14 @@ snapshots: hoist-non-react-statics: 3.3.2 i18next: 21.10.0 i18next-fs-backend: 1.2.0 - next: 15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + next: 15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) react: 18.3.1 react-i18next: 11.18.6(i18next@21.10.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) transitivePeerDependencies: - react-dom - react-native - next@15.1.7(react-dom@18.3.1(react@18.3.1))(react@18.3.1): + next@15.1.7(patch_hash=2cf73b70a6661c14b83ebd01d193260f13fcc654e74e5658ffc191f538863a49)(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: '@next/env': 15.1.7 '@swc/counter': 0.1.3
pkgs/by-name/ho/homepage-dashboard/update.sh 0 → 100755 +66 −0 Original line number Diff line number Diff line #!/usr/bin/env nix-shell #!nix-shell -I nixpkgs=./. -i bash -p curl jq git pnpm_10 sd # shellcheck shell=bash set -euo pipefail nixpkgs="$(pwd)" cd $(readlink -e $(dirname "${BASH_SOURCE[0]}")) # Generate the patch file that makes homepage-dashboard aware of the NIXPKGS_HOMEPAGE_CACHE_DIR environment variable. # Generating the patch this way ensures that both the patch is included, and the lock file is updated. generate_patch() { local version; version="$1" echo "Generating homepage-dashboard patch" git clone -b "v$version" https://github.com/gethomepage/homepage.git src pushd src pnpm install pnpm patch next sd \ 'this.serverDistDir = ctx.serverDistDir;' \ 'this.serverDistDir = require("path").join((process.env.NIXPKGS_HOMEPAGE_CACHE_DIR || "/var/cache/homepage-dashboard"), "homepage");' \ node_modules/.pnpm_patches/next*/dist/server/lib/incremental-cache/file-system-cache.js pnpm patch-commit node_modules/.pnpm_patches/next* git add -A . git diff -p --staged > ../prerender_cache_path.patch popd rm -rf src } # Update the hash of the homepage-dashboard source code in the Nix expression. update_homepage_dashboard_source() { local version; version="$1" echo "Updating homepage-dashboard source" old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.src.outputHash" | jq -r)" old_version="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.version" | jq -r)" new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).homepage-dashboard.src; in (src.overrideAttrs or (f: src // f src)) (_: { version = \"$version\"; outputHash = \"\"; outputHashAlgo = \"sha256\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true sed -i "s|${old_hash}|${new_hash}|g" package.nix sed -i "s|${old_version}|${version}|g" package.nix } # Update the hash of the homepage-dashboard pnpm dependencies in the Nix expression. update_pnpm_deps_hash() { echo "Updating homepage-dashboard pnpm deps hash" old_hash="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.pnpmDeps.outputHash" | jq -r)" new_hash="$(nix-build --impure --expr "let src = (import $nixpkgs/default.nix {}).homepage-dashboard.pnpmDeps; in (src.overrideAttrs or (f: src // f src)) (_: { outputHash = \"\"; outputHashAlgo = \"sha256\"; })" 2>&1 | tr -s ' ' | grep -Po "got: \K.+$")" || true sed -i "s|${old_hash}|${new_hash}|g" package.nix } LATEST_TAG="$(curl -s ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} https://api.github.com/repos/gethomepage/homepage/releases/latest | jq -r '.tag_name')" LATEST_VERSION="$(expr "$LATEST_TAG" : 'v\(.*\)')" CURRENT_VERSION="$(nix eval --json --impure --expr "(import $nixpkgs/default.nix {}).homepage-dashboard.version" | jq -r)" if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then echo "homepage-dashboard is up to date: ${CURRENT_VERSION}" exit 0 fi update_homepage_dashboard_source "$LATEST_VERSION" generate_patch "$LATEST_VERSION" update_pnpm_deps_hash