sm64ex: split out baserom derivation for easier reuse and nixfmt run

This commit is contained in:
Shelvacu 2024-09-24 12:24:18 -07:00
parent 801534d649
commit c78e67859b
5 changed files with 98 additions and 65 deletions

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

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

View File

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

View File

@ -1,39 +1,33 @@
{ pname {
, version pname,
, src version,
, extraNativeBuildInputs ? [ ] src,
, extraBuildInputs ? [ ] extraNativeBuildInputs ? [ ],
, extraMeta ? { } extraBuildInputs ? [ ],
, compileFlags ? [ ] extraMeta ? { },
, postInstall ? "" compileFlags ? [ ],
, region ? "us" postInstall ? "",
region ? "us",
, lib lib,
, stdenv stdenv,
, python3 python3,
, pkg-config pkg-config,
, audiofile audiofile,
, SDL2 SDL2,
, hexdump hexdump,
, requireFile sm64baserom,
, 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};
}
}: }:
let
baseRom = (sm64baserom.override { inherit region; }).romPath;
in
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
inherit pname version src postInstall; inherit
pname
version
src
postInstall
;
nativeBuildInputs = [ nativeBuildInputs = [
python3 python3
@ -48,11 +42,14 @@ stdenv.mkDerivation rec {
enableParallelBuilding = true; enableParallelBuilding = true;
makeFlags = [ makeFlags =
"VERSION=${region}" [
] ++ lib.optionals stdenv.hostPlatform.isDarwin [ "VERSION=${region}"
"OSX_BUILD=1" ]
] ++ compileFlags; ++ lib.optionals stdenv.hostPlatform.isDarwin [
"OSX_BUILD=1"
]
++ compileFlags;
preBuild = '' preBuild = ''
patchShebangs extract_assets.py patchShebangs extract_assets.py
@ -68,16 +65,20 @@ stdenv.mkDerivation rec {
runHook postInstall runHook postInstall
''; '';
meta = with lib; { meta =
longDescription = with lib;
extraMeta.description or "Super Mario 64 port based off of decompilation" + "\n" + '' {
longDescription = ''
${extraMeta.description or "Super Mario 64 port based off of decompilation"}
Note that you must supply a baserom yourself to extract assets from. 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 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. If you would like to use patches sm64ex distributes as makeflags, add them to the "compileFlags" attribute.
''; '';
mainProgram = "sm64ex"; mainProgram = "sm64ex";
license = licenses.unfree; license = licenses.unfree;
maintainers = [ ]; maintainers = [ ];
platforms = platforms.unix; platforms = platforms.unix;
} // extraMeta; }
// extraMeta;
} }

View File

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