From 72bdfe866b97efdf07dbe3a985a866eb53ef997a Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Sun, 23 Nov 2025 20:20:06 +0100 Subject: [PATCH] lemmy-ui: fix asset URLs As `fetchFromGitHub` does not preserve the `.git` directory, lemmy-ui fails to derive the value for its `COMMIT_HASH` variable during the build. The package previously (and mistakenly) assumed that `src.rev` would somehow return the commit hash and not the version. Fortunately, we do not need to know the precise commit rev. This value is only used to generate the templated URLs without further processing (and is also only injected for cache invalidation). --- nixos/modules/services/web-apps/lemmy.nix | 2 +- pkgs/servers/web-apps/lemmy/ui.nix | 34 ++++++++++------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/nixos/modules/services/web-apps/lemmy.nix b/nixos/modules/services/web-apps/lemmy.nix index d75ecb4fa02e..662007d40640 100644 --- a/nixos/modules/services/web-apps/lemmy.nix +++ b/nixos/modules/services/web-apps/lemmy.nix @@ -210,7 +210,7 @@ in root * ${cfg.ui.package}/dist file_server } - handle_path /static/${cfg.ui.package.passthru.commit_sha}/* { + handle_path /static/${cfg.ui.package.version}/* { root * ${cfg.ui.package}/dist file_server } diff --git a/pkgs/servers/web-apps/lemmy/ui.nix b/pkgs/servers/web-apps/lemmy/ui.nix index 298f1d8f3d4d..6b4294db9a32 100644 --- a/pkgs/servers/web-apps/lemmy/ui.nix +++ b/pkgs/servers/web-apps/lemmy/ui.nix @@ -18,15 +18,13 @@ stdenvNoCC.mkDerivation (finalAttrs: { pname = "lemmy-ui"; version = pinData.uiVersion; - src = - with finalAttrs; - fetchFromGitHub { - owner = "LemmyNet"; - repo = "lemmy-ui"; - rev = version; - fetchSubmodules = true; - hash = pinData.uiHash; - }; + src = fetchFromGitHub { + owner = "LemmyNet"; + repo = "lemmy-ui"; + tag = finalAttrs.version; + fetchSubmodules = true; + hash = pinData.uiHash; + }; nativeBuildInputs = [ nodejs @@ -48,20 +46,17 @@ stdenvNoCC.mkDerivation (finalAttrs: { buildPhase = '' runHook preBuild - pnpm build:prod + pnpm run prebuild:prod + # Required to pass a custom value for COMMIT_HASH, as the normal + # `pnpm build:prod` tries to derive its value by running `git`. + # This value is only injected into the templated asset URLs for cache invalidation, + # so we don't really need a commit hash here, just a value that changes on every + # update. + pnpm exec webpack --env COMMIT_HASH="${finalAttrs.version}" --mode=production runHook postBuild ''; - # installPhase = '' - # runHook preInstall - - # mkdir -p $out/{bin,lib/${finalAttrs.pname}} - # mv {dist,node_modules} $out/lib/${finalAttrs.pname} - - # runHook postInstall - - # ''; preInstall = '' mkdir $out cp -R ./dist $out @@ -81,7 +76,6 @@ stdenvNoCC.mkDerivation (finalAttrs: { passthru = { updateScript = ./update.py; tests.lemmy-ui = nixosTests.lemmy; - commit_sha = finalAttrs.src.rev; }; meta = {