stash: Refactor to use finalAttrs, straighten out src references

Previously, it was somewhat difficult to override the source tree for
stash: The `src` attribute was used in several places, some of which 
were unreachable. Now, using the `finalAttrs` argument, both the go
and yarn builds can use the same source tree, overriding it only once.

This change also adds a `postPatch` attribute, whose sole purpose is 
to copy the yarn build result into place, which again makes it easier
to override the source tree without having to duplicate the 
load-bearing other items on `preBuild`.
This commit is contained in:
Andreas Fuchs
2025-09-12 15:42:55 -04:00
parent 3a25ec26ff
commit 5af62df6ef

View File

@@ -21,22 +21,18 @@ let
; ;
pname = "stash"; pname = "stash";
in
src = fetchFromGitHub { buildGoModule (
owner = "stashapp"; finalAttrs:
repo = "stash"; let
tag = "v${version}";
hash = srcHash;
};
frontend = stdenv.mkDerivation (final: { frontend = stdenv.mkDerivation (final: {
inherit version; pname = "${finalAttrs.pname}-ui";
pname = "${pname}-ui"; inherit (finalAttrs) version gitHash;
src = "${src}/ui/v2.5"; src = "${finalAttrs.src}/ui/v2.5";
yarnOfflineCache = fetchYarnDeps { yarnOfflineCache = fetchYarnDeps {
yarnLock = "${final.src}/yarn.lock"; yarnLock = "${final.src}/yarn.lock";
hash = yarnHash; hash = finalAttrs.yarnHash;
}; };
nativeBuildInputs = [ nativeBuildInputs = [
@@ -48,7 +44,7 @@ let
postPatch = '' postPatch = ''
substituteInPlace codegen.ts \ substituteInPlace codegen.ts \
--replace-fail "../../graphql/" "${src}/graphql/" --replace-fail "../../graphql/" "${finalAttrs.src}/graphql/"
''; '';
buildPhase = '' buildPhase = ''
@@ -56,8 +52,8 @@ let
export HOME=$(mktemp -d) export HOME=$(mktemp -d)
export VITE_APP_DATE='1970-01-01 00:00:00' export VITE_APP_DATE='1970-01-01 00:00:00'
export VITE_APP_GITHASH=${gitHash} export VITE_APP_GITHASH=${finalAttrs.gitHash}
export VITE_APP_STASH_VERSION=v${version} export VITE_APP_STASH_VERSION=v${finalAttrs.version}
export VITE_APP_NOLEGACY=true export VITE_APP_NOLEGACY=true
yarn --offline run gqlgen yarn --offline run gqlgen
@@ -71,21 +67,29 @@ let
dontInstall = true; dontInstall = true;
dontFixup = true; dontFixup = true;
}); });
in in
buildGoModule { {
inherit inherit
pname pname
src
version version
gitHash
yarnHash
vendorHash vendorHash
; ;
src = fetchFromGitHub {
owner = "stashapp";
repo = "stash";
tag = "v${finalAttrs.version}";
hash = srcHash;
};
ldflags = [ ldflags = [
"-s" "-s"
"-w" "-w"
"-X 'github.com/stashapp/stash/internal/build.buildstamp=1970-01-01 00:00:00'" "-X 'github.com/stashapp/stash/internal/build.buildstamp=1970-01-01 00:00:00'"
"-X 'github.com/stashapp/stash/internal/build.githash=${gitHash}'" "-X 'github.com/stashapp/stash/internal/build.githash=${finalAttrs.gitHash}'"
"-X 'github.com/stashapp/stash/internal/build.version=v${version}'" "-X 'github.com/stashapp/stash/internal/build.version=v${finalAttrs.version}'"
"-X 'github.com/stashapp/stash/internal/build.officialBuild=false'" "-X 'github.com/stashapp/stash/internal/build.officialBuild=false'"
]; ];
tags = [ tags = [
@@ -95,8 +99,11 @@ buildGoModule {
subPackages = [ "cmd/stash" ]; subPackages = [ "cmd/stash" ];
preBuild = '' postPatch = ''
cp -a ${frontend} ui/v2.5/build cp -a ${frontend} ui/v2.5/build
'';
preBuild = ''
# `go mod tidy` requires internet access and does nothing # `go mod tidy` requires internet access and does nothing
echo "skip_mod_tidy: true" >> gqlgen.yml echo "skip_mod_tidy: true" >> gqlgen.yml
# remove `-trimpath` fron `GOFLAGS` because `gqlgen` does not work with it # remove `-trimpath` fron `GOFLAGS` because `gqlgen` does not work with it
@@ -112,7 +119,7 @@ buildGoModule {
inherit (nixosTests) stash; inherit (nixosTests) stash;
version = testers.testVersion { version = testers.testVersion {
package = stash; package = stash;
version = "v${version} (${gitHash}) - Unofficial Build - 1970-01-01 00:00:00"; version = "v${finalAttrs.version} (${finalAttrs.gitHash}) - Unofficial Build - 1970-01-01 00:00:00";
}; };
}; };
}; };
@@ -122,7 +129,7 @@ buildGoModule {
description = "Organizer for your adult videos/images"; description = "Organizer for your adult videos/images";
license = lib.licenses.agpl3Only; license = lib.licenses.agpl3Only;
homepage = "https://stashapp.cc/"; homepage = "https://stashapp.cc/";
changelog = "https://github.com/stashapp/stash/blob/v${version}/ui/v2.5/src/docs/en/Changelog/v${lib.versions.major version}${lib.versions.minor version}0.md"; changelog = "https://github.com/stashapp/stash/blob/v${finalAttrs.version}/ui/v2.5/src/docs/en/Changelog/v${lib.versions.major finalAttrs.version}${lib.versions.minor finalAttrs.version}0.md";
maintainers = with lib.maintainers; [ maintainers = with lib.maintainers; [
Golo300 Golo300
DrakeTDL DrakeTDL
@@ -134,4 +141,5 @@ buildGoModule {
"aarch64-darwin" "aarch64-darwin"
]; ];
}; };
} }
)