-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starsector: add packaging infrastructure for parsing mod files
This adds a the mkStarsectorMod helper function. It can produce Starsector mod packages that are then passed to linkFarm to be processed by the game. Signed-off-by: Fernando Rodrigues <[email protected]>
- Loading branch information
1 parent
5de106a
commit fedc2f1
Showing
2 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
lib, | ||
stdenvNoCC, | ||
fetchzip, | ||
runCommand, | ||
unrar, | ||
starsector, | ||
jq, | ||
dos2unix, | ||
}: | ||
|
||
let | ||
semiOptionalInput = | ||
input: bool: | ||
"mkStarsectorMod needs an '${input}' attribute, or 'isStandardSrc' set to '${toString bool}'."; | ||
mkStarsectorMod = | ||
{ | ||
pname, | ||
version, | ||
isStandardSrc ? true, | ||
src ? if isStandardSrc then "" else throw semiOptionalInput "src" true, | ||
url ? if !isStandardSrc then "" else throw semiOptionalInput "url" false, | ||
hash ? if !isStandardSrc then "" else throw semiOptionalInput "hash" false, | ||
author ? "", | ||
prettyName ? "", | ||
summary ? "", | ||
description ? "", | ||
forumURL ? "", | ||
}: | ||
|
||
stdenvNoCC.mkDerivation (finalAttrs: { | ||
inherit version pname; | ||
|
||
src = | ||
if isStandardSrc then | ||
fetchzip { | ||
inherit url hash; | ||
nativeBuildInputs = lib.optional (lib.hasSuffix ".rar" url) unrar; | ||
postFetch = '' | ||
if test -e "$out"/mod_info.json; then | ||
return 0; else | ||
results="$(find $out -type d -exec test -e '{}'/mod_info.json \; -print)" | ||
if [ "$(echo "$results" | wc -l)" = 1 ]; then | ||
mv "$results"/* . && rm -rf "$results"; else; | ||
echo "Starsector mod: '${pname}' has more than one mod_info.json." && exit 1 | ||
fi | ||
fi | ||
''; | ||
} | ||
else | ||
src; | ||
|
||
dontConfigure = true; | ||
dontBuild = true; | ||
|
||
installPhase = "mkdir $out && cp -prvd * $out"; | ||
|
||
passthru = { | ||
inherit author prettyName forumURL; | ||
tests = { | ||
gameVersionMatches = | ||
runCommand "${finalAttrs.pname}-gameVersionMatchTest" | ||
{ | ||
nativeBuildInputs = [ | ||
jq | ||
dos2unix | ||
]; | ||
} | ||
'' | ||
dos2unix ${finalAttrs.finalPackage}/mod_info.json | ||
modVersion="$(jq -n -f ${finalAttrs.finalPackage}/mod_info.json | jq -cMj .gameVersion)" | ||
gameVersion="${starsector.version}" | ||
if [ "$gameVersion" = "$modVersion" ]; then | ||
echo "Mod version matches!" && echo "Success: ${finalAttrs.pname}" >> $out | ||
else | ||
echo "Mod version did not match! Tried comparing '$gameVersion' to '$modVersion'." | ||
exit 1 | ||
fi | ||
''; | ||
}; | ||
}; | ||
|
||
meta = { | ||
description = "Starsector Mod: ${prettyName}"; | ||
longDescription = | ||
(if (lib.hasPrefix summary description) then description else "${summary}\n${description}") | ||
+ "\n- by ${author}."; | ||
homepage = forumURL; | ||
sourceProvenance = lib.optional (lib.pathIsDirectory ( | ||
finalAttrs.src + /jars | ||
)) lib.sourceTypes.binaryBytecode; | ||
inherit (starsector.meta) | ||
license | ||
maintainers | ||
platforms | ||
badPlatforms | ||
; | ||
}; | ||
}); | ||
in | ||
{ | ||
inherit mkStarsectorMod; | ||
} | ||
|
||
# TODO: Somehow parse the very non-standard mess that are | ||
# Starsector mods. There are mod packages that include two mods | ||
# in a single zip, some mods just straight up use invalid JSON, | ||
# while others can only be accessed through impermanent source | ||
# directories and/or lack a versioned URL. Oh, did I mention the | ||
# lack of consistent line endings? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters