From 849dea57ace50cbb7d4b116d8c63f37c3d1f2d75 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 18 Mar 2025 19:27:47 +0000 Subject: [PATCH 1/8] homepage-dashboard: 0.10.9 -> 1.0.4 This commit bumps homepage-dashboard to 1.0.4, but also introduces a different build method. The upstream project uses pnpm, and no longer ships a package.json, so it's easiest for us to follow and use pnpm. In this commit, we move to building with pnpm, but also need to change the patching methodology. pnpm has the ability to carry patches locally against dependencies, but it also hashes the patch and checks the hash before build, which means the patch will need to be updated each time to include the change to package.json, pnpm-lock.yaml and the actual file changed. In a later commit, I'll introduce an update script to do this automatically. --- pkgs/servers/homepage-dashboard/default.nix | 72 ++++++------ .../prerender_cache_path.patch | 107 +++++++++++++++--- 2 files changed, 128 insertions(+), 51 deletions(-) diff --git a/pkgs/servers/homepage-dashboard/default.nix b/pkgs/servers/homepage-dashboard/default.nix index 9efcf8e247da..fd121b7a5b53 100644 --- a/pkgs/servers/homepage-dashboard/default.nix +++ b/pkgs/servers/homepage-dashboard/default.nix @@ -1,7 +1,9 @@ { - buildNpmPackage, fetchFromGitHub, nodePackages, + makeWrapper, + nodejs, + pnpm_10, python3, stdenv, cctools, @@ -26,30 +28,37 @@ 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="; + rev = "v${finalAttrs.version}"; + hash = "sha256-7fi7cW+DKjU9CeVEg863UGwCqTXxA1UrwlK2vrx1c5w="; }; - npmDepsHash = "sha256-N39gwct2U4UxlIL5ceDzzU7HpA6xh2WksrZNxGz04PU="; + # This patch ensures that the cache implementation respects the env + # variable `NIXPKGS_HOMEPAGE_CACHE_DIR`, which is set by default in the + # wrapper below. + patches = [ ./prerender_cache_path.patch ]; - preBuild = '' - mkdir -p config - ''; + pnpmDeps = pnpm_10.fetchDeps { + inherit (finalAttrs) + pname + version + src + patches + ; + hash = "sha256-E16+JLtfoiWCXwgFGdTGuFlx/pYxhINNl6tCuF9Z6MQ="; + }; - 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 - ''; - - nativeBuildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; + nativeBuildInputs = [ + makeWrapper + nodejs + pnpm_10.configHook + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; buildInputs = [ nodePackages.node-gyp-build @@ -57,32 +66,29 @@ buildNpmPackage rec { 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 ""} @@ -100,7 +106,7 @@ buildNpmPackage rec { 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; @@ -108,4 +114,4 @@ buildNpmPackage rec { platforms = lib.platforms.all; broken = stdenv.hostPlatform.isDarwin; }; -} +}) diff --git a/pkgs/servers/homepage-dashboard/prerender_cache_path.patch b/pkgs/servers/homepage-dashboard/prerender_cache_path.patch index 1d8c3b34384a..6916c8ba8412 100644 --- a/pkgs/servers/homepage-dashboard/prerender_cache_path.patch +++ b/pkgs/servers/homepage-dashboard/prerender_cache_path.patch @@ -1,18 +1,89 @@ -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.NIXPKGS_HOMEPAGE_CACHE_DIR, "homepage"); - this.appDir = !!ctx._appDir; - if (ctx.maxMemoryCacheSize) { - this.memoryCache = new _lruCache.default({ +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 From f606c72fac5d55f5ad87637cea4d0bfc2aee0cd8 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Tue, 18 Mar 2025 19:28:42 +0000 Subject: [PATCH 2/8] homepage-dashboard: add update script Since we now need to patch dependencies through pnpm, and that results in a changed lock file that carries hashes for updated dependencies, it seems sensible to script the generation of the patch such that bots can do it, and the process is somewhat documented. --- pkgs/servers/homepage-dashboard/default.nix | 4 +- pkgs/servers/homepage-dashboard/update.sh | 66 +++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100755 pkgs/servers/homepage-dashboard/update.sh diff --git a/pkgs/servers/homepage-dashboard/default.nix b/pkgs/servers/homepage-dashboard/default.nix index fd121b7a5b53..76a08bfec7e6 100644 --- a/pkgs/servers/homepage-dashboard/default.nix +++ b/pkgs/servers/homepage-dashboard/default.nix @@ -11,7 +11,6 @@ lib, nixosTests, enableLocalIcons ? false, - nix-update-script, }: let dashboardIcons = fetchFromGitHub { @@ -42,6 +41,7 @@ stdenv.mkDerivation (finalAttrs: { # 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 { @@ -101,7 +101,7 @@ stdenv.mkDerivation (finalAttrs: { tests = { inherit (nixosTests) homepage-dashboard; }; - updateScript = nix-update-script { }; + updateScript = ./update.sh; }; meta = { diff --git a/pkgs/servers/homepage-dashboard/update.sh b/pkgs/servers/homepage-dashboard/update.sh new file mode 100755 index 000000000000..4b5069626263 --- /dev/null +++ b/pkgs/servers/homepage-dashboard/update.sh @@ -0,0 +1,66 @@ +#!/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" default.nix + sed -i "s|${old_version}|${version}|g" default.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" default.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="$(grep -Po "version = \"\K[^\"]+" default.nix)" + +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 From 6b178a410df08f4e864886fcebf6d34248bd0025 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Wed, 19 Mar 2025 09:54:31 +0000 Subject: [PATCH 3/8] homepage-dashboard: move to `pkgs/by-name` --- .../ho/homepage-dashboard/package.nix} | 4 ++-- .../ho}/homepage-dashboard/prerender_cache_path.patch | 0 pkgs/{servers => by-name/ho}/homepage-dashboard/update.sh | 8 ++++---- pkgs/top-level/all-packages.nix | 4 ---- 4 files changed, 6 insertions(+), 10 deletions(-) rename pkgs/{servers/homepage-dashboard/default.nix => by-name/ho/homepage-dashboard/package.nix} (96%) rename pkgs/{servers => by-name/ho}/homepage-dashboard/prerender_cache_path.patch (100%) rename pkgs/{servers => by-name/ho}/homepage-dashboard/update.sh (90%) diff --git a/pkgs/servers/homepage-dashboard/default.nix b/pkgs/by-name/ho/homepage-dashboard/package.nix similarity index 96% rename from pkgs/servers/homepage-dashboard/default.nix rename to pkgs/by-name/ho/homepage-dashboard/package.nix index 76a08bfec7e6..86312d3f06e9 100644 --- a/pkgs/servers/homepage-dashboard/default.nix +++ b/pkgs/by-name/ho/homepage-dashboard/package.nix @@ -7,7 +7,7 @@ python3, stdenv, cctools, - IOKit, + darwin, lib, nixosTests, enableLocalIcons ? false, @@ -62,7 +62,7 @@ stdenv.mkDerivation (finalAttrs: { 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"; diff --git a/pkgs/servers/homepage-dashboard/prerender_cache_path.patch b/pkgs/by-name/ho/homepage-dashboard/prerender_cache_path.patch similarity index 100% rename from pkgs/servers/homepage-dashboard/prerender_cache_path.patch rename to pkgs/by-name/ho/homepage-dashboard/prerender_cache_path.patch diff --git a/pkgs/servers/homepage-dashboard/update.sh b/pkgs/by-name/ho/homepage-dashboard/update.sh similarity index 90% rename from pkgs/servers/homepage-dashboard/update.sh rename to pkgs/by-name/ho/homepage-dashboard/update.sh index 4b5069626263..e8f0ced770c5 100755 --- a/pkgs/servers/homepage-dashboard/update.sh +++ b/pkgs/by-name/ho/homepage-dashboard/update.sh @@ -38,8 +38,8 @@ update_homepage_dashboard_source() { 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" default.nix - sed -i "s|${old_version}|${version}|g" default.nix + 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. @@ -49,12 +49,12 @@ update_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" default.nix + 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="$(grep -Po "version = \"\K[^\"]+" default.nix)" +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}" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d151a09dbac7..6d00dbd901aa 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2328,10 +2328,6 @@ with pkgs; hocr-tools = with python3Packages; toPythonApplication hocr-tools; - homepage-dashboard = callPackage ../servers/homepage-dashboard { - inherit (darwin.apple_sdk.frameworks) IOKit; - }; - hopper = qt5.callPackage ../development/tools/analysis/hopper { }; hypr = callPackage ../applications/window-managers/hyprwm/hypr { From eb324777e9230756624b3f07a01430c07d5cc07d Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Wed, 19 Mar 2025 11:03:55 +0000 Subject: [PATCH 4/8] nixos/homepage-dashboard: remove unmanaged config support This has been deprecated since before 24.05 was released and displaying a warning. This change means that only "managed", i.e. Nix-native configurations are supported. --- .../services/misc/homepage-dashboard.nix | 124 +++++++----------- 1 file changed, 47 insertions(+), 77 deletions(-) diff --git a/nixos/modules/services/misc/homepage-dashboard.nix b/nixos/modules/services/misc/homepage-dashboard.nix index 3a3bc8f6d60e..193f70784087 100644 --- a/nixos/modules/services/misc/homepage-dashboard.nix +++ b/nixos/modules/services/misc/homepage-dashboard.nix @@ -192,82 +192,52 @@ 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 { - "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 = - settingsFormat.generate "kubernetes.yaml" cfg.kubernetes; - "homepage-dashboard/services.yaml".source = settingsFormat.generate "services.yaml" cfg.services; - "homepage-dashboard/settings.yaml".source = settingsFormat.generate "settings.yaml" cfg.settings; - "homepage-dashboard/widgets.yaml".source = settingsFormat.generate "widgets.yaml" cfg.widgets; - }; - - systemd.services.homepage-dashboard = { - description = "Homepage Dashboard"; - after = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - - environment = { - HOMEPAGE_CONFIG_DIR = configDir; - NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard"; - PORT = toString cfg.listenPort; - LOG_TARGETS = lib.mkIf managedConfig "stdout"; - }; - - serviceConfig = { - Type = "simple"; - DynamicUser = true; - EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; - StateDirectory = lib.mkIf (!managedConfig) "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:?}"/* - ''; - }; - - networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ cfg.listenPort ]; - }; + 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 = + settingsFormat.generate "kubernetes.yaml" cfg.kubernetes; + "homepage-dashboard/services.yaml".source = settingsFormat.generate "services.yaml" cfg.services; + "homepage-dashboard/settings.yaml".source = settingsFormat.generate "settings.yaml" cfg.settings; + "homepage-dashboard/widgets.yaml".source = settingsFormat.generate "widgets.yaml" cfg.widgets; }; + + systemd.services.homepage-dashboard = { + description = "Homepage Dashboard"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + environment = { + HOMEPAGE_CONFIG_DIR = "/etc/homepage-dashboard"; + NIXPKGS_HOMEPAGE_CACHE_DIR = "/var/cache/homepage-dashboard"; + PORT = toString cfg.listenPort; + LOG_TARGETS = "stdout"; + }; + + serviceConfig = { + Type = "simple"; + DynamicUser = true; + EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; + StateDirectory = "homepage-dashboard"; + CacheDirectory = "homepage-dashboard"; + ExecStart = lib.getExe cfg.package; + Restart = "on-failure"; + }; + + 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"/* + ''; + }; + + networking.firewall = lib.mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.listenPort ]; + }; + }; } From 4240d073c71cdbc69e33844574b5cd6d045471a6 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Wed, 19 Mar 2025 11:05:40 +0000 Subject: [PATCH 5/8] nixosTests.homepage-dashboard: remove unmanaged conf tests --- nixos/tests/homepage-dashboard.nix | 43 ++++++++---------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/nixos/tests/homepage-dashboard.nix b/nixos/tests/homepage-dashboard.nix index 7fb30d473e00..ed70ead01820 100644 --- a/nixos/tests/homepage-dashboard.nix +++ b/nixos/tests/homepage-dashboard.nix @@ -4,46 +4,25 @@ 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, ... }: - { - services.homepage-dashboard = { - enable = true; - settings.title = "test title rodUsEagid"; # something random/unique - }; + nodes.machine = _: { + services.homepage-dashboard = { + enable = true; + settings.title = "test title rodUsEagid"; # something random/unique }; + }; 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" ''; } ) From b3e43663761d128b032af6dcce87c7f845c40bec Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Thu, 20 Mar 2025 11:58:39 +0000 Subject: [PATCH 6/8] homepage-dashboard: use `tag` not `rev`; use `makeBinWrapper` --- pkgs/by-name/ho/homepage-dashboard/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/ho/homepage-dashboard/package.nix b/pkgs/by-name/ho/homepage-dashboard/package.nix index 86312d3f06e9..3189cbeacb15 100644 --- a/pkgs/by-name/ho/homepage-dashboard/package.nix +++ b/pkgs/by-name/ho/homepage-dashboard/package.nix @@ -1,7 +1,7 @@ { fetchFromGitHub, nodePackages, - makeWrapper, + makeBinaryWrapper, nodejs, pnpm_10, python3, @@ -34,7 +34,7 @@ stdenv.mkDerivation (finalAttrs: { src = fetchFromGitHub { owner = "gethomepage"; repo = "homepage"; - rev = "v${finalAttrs.version}"; + tag = "v${finalAttrs.version}"; hash = "sha256-7fi7cW+DKjU9CeVEg863UGwCqTXxA1UrwlK2vrx1c5w="; }; @@ -55,7 +55,7 @@ stdenv.mkDerivation (finalAttrs: { }; nativeBuildInputs = [ - makeWrapper + makeBinaryWrapper nodejs pnpm_10.configHook ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; From 737bf8c806de5dc8cffa8e5216d7964d9d87d9b4 Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Thu, 20 Mar 2025 11:58:54 +0000 Subject: [PATCH 7/8] nixos/homepage-dashboard: minor refactor for readability --- nixos/modules/services/misc/homepage-dashboard.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/misc/homepage-dashboard.nix b/nixos/modules/services/misc/homepage-dashboard.nix index 193f70784087..7d8bf8ddfd37 100644 --- a/nixos/modules/services/misc/homepage-dashboard.nix +++ b/nixos/modules/services/misc/homepage-dashboard.nix @@ -227,11 +227,11 @@ in Restart = "on-failure"; }; + # 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") 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"/* ''; }; From 60ec94a629d2345bd98f56c1d3d2ef3df00befef Mon Sep 17 00:00:00 2001 From: Jon Seager Date: Sun, 23 Mar 2025 09:59:33 +0000 Subject: [PATCH 8/8] homepage-dashboard: update source/pnpm hashes --- pkgs/by-name/ho/homepage-dashboard/package.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/ho/homepage-dashboard/package.nix b/pkgs/by-name/ho/homepage-dashboard/package.nix index 3189cbeacb15..0e45b05f6ed6 100644 --- a/pkgs/by-name/ho/homepage-dashboard/package.nix +++ b/pkgs/by-name/ho/homepage-dashboard/package.nix @@ -35,7 +35,7 @@ stdenv.mkDerivation (finalAttrs: { owner = "gethomepage"; repo = "homepage"; tag = "v${finalAttrs.version}"; - hash = "sha256-7fi7cW+DKjU9CeVEg863UGwCqTXxA1UrwlK2vrx1c5w="; + hash = "sha256-SwzgmVy3TBzEH+FJ/kY+iCo+pZhud1IZkfCh2DiSTsk="; }; # This patch ensures that the cache implementation respects the env @@ -51,7 +51,7 @@ stdenv.mkDerivation (finalAttrs: { src patches ; - hash = "sha256-E16+JLtfoiWCXwgFGdTGuFlx/pYxhINNl6tCuF9Z6MQ="; + hash = "sha256-GUDSfAbBK+6Bbih5jBrkjiMYLOJM7gMfurXFeez1bSw="; }; nativeBuildInputs = [