Add package sm64coopdx (#344305)

This commit is contained in:
Colin 2024-11-23 14:04:40 +00:00 committed by GitHub
commit bcf111d082
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 233 additions and 65 deletions

View File

@ -20167,6 +20167,13 @@
githubId = 251028;
name = "Shell Turner";
};
shelvacu = {
name = "Shelvacu";
email = "nix-maint@shelvacu.com";
matrix = "@s:consortium.chat";
github = "shelvacu";
githubId = 1731537;
};
shhht = {
name = "shhht";
email = "stp.tjeerd@gmail.com";

View File

@ -0,0 +1,39 @@
{
requireFile,
runCommand,
region ? "us",
showRegionMessage ? true,
}:
# nixpkgs assumes that a file derivation is a setup script and tries to load it, so we have to put this in a directory
let
file = requireFile {
name = "baserom.${region}.z64";
message = ''
This nix expression requires that baserom.${region}.z64 is
already part of the store. To get this file you can dump your Super Mario 64 cartridge's contents
and add it to the nix store with nix-store --add-fixed sha256 <FILE>.
${
if showRegionMessage then
''Note that if you are not using a US baserom, you must overwrite the "region" attribute with either "eu" or "jp".''
else
""
}
'';
sha256 =
{
"us" = "17ce077343c6133f8c9f2d6d6d9a4ab62c8cd2aa57c40aea1f490b4c8bb21d91";
"eu" = "c792e5ebcba34c8d98c0c44cf29747c8ee67e7b907fcc77887f9ff2523f80572";
"jp" = "9cf7a80db321b07a8d461fe536c02c87b7412433953891cdec9191bfad2db317";
}
.${region};
};
result = runCommand "baserom-${region}-safety-dir" { } ''
mkdir $out
ln -s ${file} $out/${file.name}
'';
in
result
// {
romPath = "${result.outPath}/${file.name}";
}

View File

@ -0,0 +1,128 @@
{
fetchFromGitHub,
lib,
makeWrapper,
writeTextFile,
curl,
hexdump,
python3,
SDL2,
stdenv,
zlib,
sm64baserom,
enableCoopNet ? true,
enableDiscord ? true,
enableTextureFix ? true,
}:
let
libc_hack = writeTextFile {
name = "libc-hack";
# https://stackoverflow.com/questions/21768542/libc-h-no-such-file-or-directory-when-compiling-nanomsg-pipeline-sample
text = ''
#include <unistd.h>
#include <string.h>
#include <pthread.h>
'';
destination = "/include/libc.h";
};
baserom =
(sm64baserom.override {
region = "us";
showRegionMessage = false;
}).romPath;
in
# note: there is a generic builder in pkgs/games/sm64ex/generic.nix that is meant to help build sm64ex and its forks; however sm64coopdx has departed significantly enough in its build that it doesn't make sense to use that other than the baseRom derivation
stdenv.mkDerivation (finalAttrs: {
pname = "sm64coopdx";
version = "1.0.3";
src = fetchFromGitHub {
owner = "coop-deluxe";
repo = "sm64coopdx";
rev = "v${finalAttrs.version}";
hash = "sha256-cIH3escLFMcHgtFxeSKIo5nZXvaknti+EVt72uB4XXc=";
};
nativeBuildInputs = [ makeWrapper ];
buildInputs = [
curl
hexdump
libc_hack
python3
SDL2
zlib
];
enableParallelBuilding = true;
makeFlags = [
"BREW_PREFIX=/not-exist"
"DISCORD_SDK=${if enableDiscord then "1" else "0"}"
"TEXTURE_FIX=${if enableTextureFix then "1" else "0"}"
"COOPNET=${if enableCoopNet then "1" else "0"}"
];
preBuild = ''
# the baserom is needed both at build time and run time
ln -s ${baserom} baserom.us.z64
# remove -march flags, stdenv manages them
substituteInPlace Makefile \
--replace-fail ' -march=$(TARGET_ARCH)' ""
# workaround a bug in the build
# see https://github.com/coop-deluxe/sm64coopdx/issues/186#issuecomment-2216163935
# this can likely be removed when the next version releases
make build/us_pc/sound/sequences.bin
'';
installPhase = ''
runHook preInstall
local built=$PWD/build/us_pc
local share=$out/share/sm64coopdx
mkdir -p $share
cp $built/sm64coopdx $share/sm64coopdx
cp -r $built/{dynos,lang,mods,palettes} $share
# the baserom is needed both at build time and run time
ln -s ${baserom} $share/baserom.us.z64
${lib.optionalString enableDiscord ''
cp $built/libdiscord_game_sdk* $share
''}
# coopdx always tries to load resources from the binary's directory, with no obvious way to change. Thus this small wrapper script to always run from the /share directory that has all the resources
mkdir -p $out/bin
makeWrapper $share/sm64coopdx $out/bin/sm64coopdx \
--chdir $share
runHook postInstall
'';
meta = {
description = "Multiplayer fork of the Super Mario 64 decompilation";
longDescription = ''
This is a fork of sm64ex-coop, which was itself a fork of sm64ex, which was a fork of the sm64 decompilation project.
It allows multiple people to play within and across levels, has multiple character models, and mods in the form of lua scripts.
Arguments:
- `enableTextureFix`: (default: `true`) whether to enable texture fixes. Upstream describes disabling this as "for purists"
- `enableDiscord`: (default: `true`) whether to enable discord integration, which allows showing status and connecting to games over discord
- `enableCoopNet`: (default: `true`) whether to enable Co-op Net integration, a server made specifically for multiplayer sm64
'';
license = lib.licenses.unfree;
platforms = lib.platforms.x86;
maintainers = [ lib.maintainers.shelvacu ];
mainProgram = "sm64coopdx";
homepage = "https://sm64coopdx.com/";
changelog = "https://github.com/coop-deluxe/sm64coopdx/releases/tag/v${finalAttrs.version}";
sourceProvenance = with lib.sourceTypes; [
fromSource
# The lua engine, discord sdk, and coopnet library are vendored pre-built. See https://github.com/coop-deluxe/sm64coopdx/tree/v1.0.3/lib
binaryNativeCode
];
};
})

View File

@ -1,8 +1,9 @@
{ callPackage
, fetchFromGitHub
, autoPatchelfHook
, zlib
, stdenvNoCC
{
callPackage,
fetchFromGitHub,
autoPatchelfHook,
zlib,
stdenvNoCC,
}:
callPackage ./generic.nix {
@ -16,13 +17,9 @@ callPackage ./generic.nix {
sha256 = "sha256-iwJsq0FN9npxveIoMiB7zL5j1V72IExtEpzGj6lwLXQ=";
};
extraNativeBuildInputs = [
autoPatchelfHook
];
extraNativeBuildInputs = [ autoPatchelfHook ];
extraBuildInputs = [
zlib
];
extraBuildInputs = [ zlib ];
postInstall =
let

View File

@ -1,9 +1,8 @@
{ callPackage
, branch
}:
{ callPackage, branch }:
{
sm64ex = callPackage ./sm64ex.nix { };
sm64ex-coop = callPackage ./coop.nix { };
}.${branch}
}
.${branch}

View File

@ -1,39 +1,33 @@
{ pname
, version
, src
, extraNativeBuildInputs ? [ ]
, extraBuildInputs ? [ ]
, extraMeta ? { }
, compileFlags ? [ ]
, postInstall ? ""
, region ? "us"
{
pname,
version,
src,
extraNativeBuildInputs ? [ ],
extraBuildInputs ? [ ],
extraMeta ? { },
compileFlags ? [ ],
postInstall ? "",
region ? "us",
, lib
, stdenv
, python3
, pkg-config
, audiofile
, SDL2
, hexdump
, requireFile
, baseRom ? requireFile {
name = "baserom.${region}.z64";
message = ''
This nix expression requires that baserom.${region}.z64 is
already part of the store. To get this file you can dump your Super Mario 64 cartridge's contents
and add it to the nix store with nix-store --add-fixed sha256 <FILE>.
Note that if you are not using a US baserom, you must overwrite the "region" attribute with either "eu" or "jp".
'';
sha256 = {
"us" = "17ce077343c6133f8c9f2d6d6d9a4ab62c8cd2aa57c40aea1f490b4c8bb21d91";
"eu" = "c792e5ebcba34c8d98c0c44cf29747c8ee67e7b907fcc77887f9ff2523f80572";
"jp" = "9cf7a80db321b07a8d461fe536c02c87b7412433953891cdec9191bfad2db317";
}.${region};
}
lib,
stdenv,
python3,
pkg-config,
audiofile,
SDL2,
hexdump,
sm64baserom,
}:
let
baseRom = (sm64baserom.override { inherit region; }).romPath;
in
stdenv.mkDerivation rec {
inherit pname version src postInstall;
inherit
pname
version
src
postInstall
;
nativeBuildInputs = [
python3
@ -48,11 +42,14 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true;
makeFlags = [
"VERSION=${region}"
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
"OSX_BUILD=1"
] ++ compileFlags;
makeFlags =
[
"VERSION=${region}"
]
++ lib.optionals stdenv.hostPlatform.isDarwin [
"OSX_BUILD=1"
]
++ compileFlags;
preBuild = ''
patchShebangs extract_assets.py
@ -68,16 +65,20 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
meta = with lib; {
longDescription =
extraMeta.description or "Super Mario 64 port based off of decompilation" + "\n" + ''
meta =
with lib;
{
longDescription = ''
${extraMeta.description or "Super Mario 64 port based off of decompilation"}
Note that you must supply a baserom yourself to extract assets from.
If you are not using an US baserom, you must overwrite the "region" attribute with either "eu" or "jp".
If you would like to use patches sm64ex distributes as makeflags, add them to the "compileFlags" attribute.
'';
mainProgram = "sm64ex";
license = licenses.unfree;
maintainers = [ ];
platforms = platforms.unix;
} // extraMeta;
mainProgram = "sm64ex";
license = licenses.unfree;
maintainers = [ ];
platforms = platforms.unix;
}
// extraMeta;
}

View File

@ -1,6 +1,4 @@
{ callPackage
, fetchFromGitHub
}:
{ callPackage, fetchFromGitHub }:
callPackage ./generic.nix {
pname = "sm64ex";
@ -18,4 +16,3 @@ callPackage ./generic.nix {
description = "Super Mario 64 port based off of decompilation";
};
}