2021-11-15 08:17:16 +00:00
# THIS IS A WORK IN PROGRESS!
2021-12-08 17:02:46 +00:00
# To save you having to build Mono locally, install the Cachix client (`nix-env -iA nixpkgs.cachix`) and run `cachix use mono-for-bizhawk` (both commands only need to run once ever). See https://docs.cachix.org for more info.
2021-11-15 08:17:16 +00:00
2021-12-01 06:31:53 +00:00
{ pkgs ? import ( fetchTarball " h t t p s : / / g i t h u b . c o m / N i x O S / n i x p k g s / a r c h i v e / 2 1 . 1 1 . t a r . g z " ) { }
2021-11-15 08:17:16 +00:00
# infrastructure
, stdenv ? pkgs . stdenvNoCC
, buildDotnetModule ? pkgs . buildDotnetModule
, fetchFromGitHub ? pkgs . fetchFromGitHub
#, makeDesktopItem ? pkgs.makeDesktopItem
, makeWrapper ? pkgs . makeWrapper
# source
2022-03-08 00:17:18 +00:00
, useCWDAsSource ? false # deprecated
, hawkSourceInfoDev ? rec {
version = " 2 . 8 . 1 - l o c a l " ; # distinguishes parallel installs' config and other data
shorthash = " 0 0 0 0 0 0 0 0 0 " ; # this and the branch name are written into movies and savestates, written to config to detect in-place upgrades (N/A to Nix), and of course also shown in the About dialog
branch = " m a s t e r " ; # must be regex-escaped (interpolated as `sed "s/.../${branch}/"`)
2022-06-13 02:03:18 +00:00
drv = builtins . path { path = ./. ; name = " B i z H a w k - ${ version } " ; } ; # did have filter here for speed, but it wasn't faster and it wasn't correct and it couldn't be made correct and I'm mad
2022-03-08 00:17:18 +00:00
}
2021-11-15 08:17:16 +00:00
# makedeps
2021-12-01 06:31:53 +00:00
, dotnet-sdk_5 ? pkgs . dotnetCorePackages . sdk_5_0
, dotnet-sdk_6 ? pkgs . dotnetCorePackages . sdk_6_0
2021-11-15 08:17:16 +00:00
# rundeps for NixOS hosts
#, gtk2-x11 ? pkgs.gtk2-x11
# rundeps for all Linux hosts
, mesa ? pkgs . mesa
2021-11-18 12:39:15 +00:00
, mono ? null
2021-11-15 08:17:16 +00:00
, openal ? pkgs . openal
, uname ? stdenv
# other parameters
, buildConfig ? " R e l e a s e " # "Debug"/"Release"
2021-12-02 05:41:15 +00:00
, debugPInvokes ? false # forwarded to Dist/wrapper-scripts.nix
2021-11-15 08:17:16 +00:00
, doCheck ? false # runs `Dist/BuildTest${buildConfig}.sh`
, forNixOS ? false
2021-12-02 05:41:15 +00:00
, initConfig ? { } # forwarded to Dist/wrapper-scripts.nix (see docs there)
2021-11-15 08:17:16 +00:00
} :
let
2021-12-02 05:41:15 +00:00
lib = pkgs . lib ;
2021-11-18 12:39:15 +00:00
commentUnless = b : lib . optionalString ( ! b ) " # " ;
2021-12-02 05:41:15 +00:00
versionAtLeast = exVer : acVer : builtins . compareVersions exVer acVer <= 0 ;
2021-11-18 12:39:15 +00:00
monoFinal = if mono != null
2021-11-15 08:17:16 +00:00
then mono
2021-12-02 05:41:15 +00:00
else if versionAtLeast " 6 . 1 2 . 0 . 1 5 1 " pkgs . mono . version
2021-11-18 12:39:15 +00:00
then pkgs . mono
2021-12-02 05:41:15 +00:00
else pkgs . callPackage Dist/mono-6.12.0.151.nix { } ; # not actually reproducible :( https://github.com/NixOS/nixpkgs/issues/143110#issuecomment-984251253
2022-03-08 00:17:18 +00:00
buildAssembliesFor = hawkSourceInfo : buildDotnetModule rec {
2021-11-15 08:17:16 +00:00
pname = " B i z H a w k " ;
2021-12-08 17:02:46 +00:00
version = hawkSourceInfo . version ;
src = hawkSourceInfo . drv ;
2021-12-13 09:33:05 +00:00
outputs = [ " b i n " " o u t " ] ;
2022-03-08 00:17:18 +00:00
dotnet-sdk = if hawkSourceInfo ? dotnet-sdk then hawkSourceInfo . dotnet-sdk else dotnet-sdk_6 ;
2021-11-15 08:17:16 +00:00
buildInputs = [ mesa monoFinal openal uname ] ; # ++ lib.optionals (forNixOS) [ gtk2-x11 ];
projectFile = " B i z H a w k . s l n " ;
2022-03-08 00:17:18 +00:00
nugetDeps = if hawkSourceInfo ? nugetDeps then hawkSourceInfo . nugetDeps else Dist/deps.nix ;
2021-11-15 08:17:16 +00:00
extraDotnetBuildFlags = " - m a x c p u c o u n t : $ N I X _ B U I L D _ C O R E S - p : B u i l d I n P a r a l l e l = t r u e - - n o - r e s t o r e " ;
2021-12-08 17:02:46 +00:00
postPatch = ''
# confused? '$(...)' is literal here
# these scripts invoke Git in subshells and we want to run them now, at compile time, without Git
sed - i ' s / $ ( git rev-parse - - verify HEAD ) / $ { hawkSourceInfo . shorthash } / ' Dist/.InvokeCLIOnMainSln.sh
sed - i - e ' s / $ ( git rev-parse - - abbrev-ref HEAD ) / $ { hawkSourceInfo . branch } / ' - e ' s / $ ( git log -1 - - format = " % h " ) / $ { hawkSourceInfo . shorthash } / ' Build/standin.sh
sed - i ' s / $ ( git rev-list HEAD - - count ) // ' Build/standin.sh # const field is unused
2021-12-13 09:33:05 +00:00
# stop MSBuild from copying Assets, we'll do that later
sed - i ' /Assets \ / \ * \ * /d ' src/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
sed - i ' /mkdir " p a c k a g e d _ o u t p u t \/ F i r m w a r e / d ' D i s t / P a c k a g e . s h # a n d w e d o n ' t n e e d t h i s
2021-12-08 17:02:46 +00:00
'' ;
2021-11-15 08:17:16 +00:00
buildPhase = ''
2022-03-08 00:17:18 +00:00
cd src/BizHawk.Version
dotnet build $ { extraDotnetBuildFlags }
cd ../..
2021-11-15 08:17:16 +00:00
Dist/Build $ { buildConfig } . sh $ { extraDotnetBuildFlags }
2022-01-27 20:00:37 +00:00
printf " N i x H a w k " > output/dll/custombuild.txt
2021-11-15 08:17:16 +00:00
Dist/Package.sh linux-x64
'' ;
inherit doCheck ;
checkPhase = ''
export GITLAB_CI = 1 # pretend to be in GitLab CI -- platform-specific tests don't run in CI because they assume an Arch filesystem (on Linux hosts)
# from 2.7.1, use standard -p:ContinuousIntegrationBuild=true instead
Dist/BuildTest $ { buildConfig } . sh $ { extraDotnetBuildFlags }
# can't build w/ extra Analyzers, it fails to restore :(
# Dist/Build${buildConfig}.sh -p:MachineRunAnalyzersDuringBuild=true ${extraDotnetBuildFlags}
'' ;
installPhase = ''
2021-12-13 09:33:05 +00:00
cp - avT packaged_output $ bin
cp - avt $ bin Assets/defctrl.json && rm Assets/defctrl.json
cp - avt $ bin/dll Assets/dll /* & & r m - r A s s e t s / d l l
rm Assets/EmuHawkMono.sh # replaced w/ scripts from wrapperScripts
cp - avt $ bin Assets/gamedb && rm - r Assets/gamedb
cp - avt $ bin Assets/Shaders && rm - r Assets/Shaders
cp - avT Assets $ out
2021-11-15 08:17:16 +00:00
'' ;
dontPatchELF = true ;
} ;
2022-03-08 00:17:18 +00:00
wrapperScriptsFor = { hawkSourceInfo , bizhawkAssemblies }: import Dist/wrapper-scripts.nix {
2021-12-02 05:41:15 +00:00
inherit ( pkgs ) lib writeShellScriptBin writeText ;
2022-03-08 00:17:18 +00:00
inherit commentUnless versionAtLeast mesa openal debugPInvokes initConfig ;
bizhawk = bizhawkAssemblies ;
2021-12-08 17:02:46 +00:00
hawkVersion = hawkSourceInfo . version ;
2021-12-02 05:41:15 +00:00
mono = monoFinal ;
} ;
2022-03-08 00:17:18 +00:00
mkWrapperWrapper = { hawkSourceInfo , bizhawkAssemblies , pname , innerWrapper , desktopName }: stdenv . mkDerivation rec {
2022-01-20 02:26:54 +00:00
inherit pname ;
2021-12-08 17:02:46 +00:00
version = hawkSourceInfo . version ;
2022-01-20 02:26:54 +00:00
exeName = " ${ pname } - ${ version } " ;
2021-11-18 12:39:15 +00:00
nativeBuildInputs = [ makeWrapper ] ;
2022-03-08 00:17:18 +00:00
buildInputs = [ bizhawkAssemblies ] ;
2021-11-18 12:39:15 +00:00
# there must be a helper for this somewhere...
dontUnpack = true ;
dontPatch = true ;
dontConfigure = true ;
dontBuild = true ;
installPhase = ''
mkdir - p $ out/bin
2022-01-20 02:26:54 +00:00
makeWrapper $ { innerWrapper } $ out/bin / $ { exeName } \
2022-03-08 00:17:18 +00:00
- - set BIZHAWK_HOME $ { bizhawkAssemblies }
2021-11-18 12:39:15 +00:00
'' ;
dontFixup = true ;
2022-01-20 02:26:54 +00:00
# desktopItems = [ (makeDesktopItem {
# name = "${pname}-${version}"; # actually filename
# exec = "${exeName}";
# inherit desktopName; # actually Name
2021-11-18 12:39:15 +00:00
# }) ];
} ;
2022-03-08 00:17:18 +00:00
buildDiscoHawkWrapperFor = { hawkSourceInfo , bizhawkAssemblies ? buildAssembliesFor hawkSourceInfo }: let
wrapperScripts = wrapperScriptsFor { inherit hawkSourceInfo bizhawkAssemblies ; } ;
in mkWrapperWrapper {
inherit hawkSourceInfo bizhawkAssemblies ;
2022-01-20 02:26:54 +00:00
pname = " d i s c o h a w k - m o n o r t " ;
innerWrapper = " ${ wrapperScripts . discoWrapper } / b i n / d i s c o h a w k - w r a p p e r " ;
desktopName = " D i s c o H a w k ( M o n o R u n t i m e ) " ;
} ;
2022-03-08 00:17:18 +00:00
buildEmuHawkWrapperFor = { hawkSourceInfo , bizhawkAssemblies ? buildAssembliesFor hawkSourceInfo }: let
wrapperScripts = wrapperScriptsFor { inherit hawkSourceInfo bizhawkAssemblies ; } ;
in mkWrapperWrapper {
inherit hawkSourceInfo bizhawkAssemblies ;
2022-01-20 02:26:54 +00:00
pname = " e m u h a w k - m o n o r t " ;
innerWrapper = if forNixOS
then " ${ wrapperScripts . wrapperScript } / b i n / e m u h a w k - w r a p p e r "
else " ${ wrapperScripts . wrapperScriptNonNixOS } / b i n / e m u h a w k - w r a p p e r - n o n - n i x o s " ;
desktopName = " E m u H a w k ( M o n o R u n t i m e ) " ;
} ;
2022-03-08 00:17:18 +00:00
in rec {
bizhawkAssemblies = buildAssembliesFor hawkSourceInfoDev ; # assemblies and dependencies, and some other immutable things like the gamedb, are in the `bin` output; the rest of the "assets" (bundled scripts, palettes, etc.) are in the `out` output
discohawk = buildDiscoHawkWrapperFor { inherit bizhawkAssemblies ; hawkSourceInfo = hawkSourceInfoDev ; } ;
emuhawk-2_7 = buildEmuHawkWrapperFor {
hawkSourceInfo = {
version = " 2 . 7 " ;
shorthash = " d b a f 2 5 9 5 6 " ;
branch = " m a s t e r " ;
drv = fetchFromGitHub {
owner = " T A S E m u l a t o r s " ;
repo = " B i z H a w k " ;
rev = " d b a f 2 5 9 5 6 2 5 f 7 9 0 9 3 e e e c 3 7 d 2 d 4 a 7 a 9 a 4 d 3 7 f 3 7 0 " ;
hash = " s h a 2 5 6 - K X e 6 9 s v P I I F a X g T 9 t + 0 2 p w d Q 6 W W q d q g U d t a E 2 S 4 / Y x A = " ;
} ;
dotnet-sdk = dotnet-sdk_5 ;
2022-07-19 15:58:49 +00:00
nugetDeps = Dist/deps_2_7.nix ;
2022-03-08 00:17:18 +00:00
} ;
} ;
emuhawk-2_8 = buildEmuHawkWrapperFor {
hawkSourceInfo = {
version = " 2 . 8 " ;
shorthash = " e 7 3 1 e 0 f 3 2 " ;
branch = " m a s t e r " ;
drv = fetchFromGitHub {
owner = " T A S E m u l a t o r s " ;
repo = " B i z H a w k " ;
rev = " e 7 3 1 e 0 f 3 2 9 0 3 c d 4 0 b 8 3 e d 7 5 b b a 3 b 1 e 3 7 5 3 1 0 5 c e 2 " ;
hash = " s h a 2 5 6 - k P 6 z v T b h c t q G C m j D O t Q g B G I I 1 T 0 x I y N 5 k e q 7 d / l f W V M = " ;
} ;
2022-07-19 15:58:49 +00:00
nugetDeps = Dist/deps_2_8.nix ;
2022-03-08 00:17:18 +00:00
} ;
} ;
emuhawk = buildEmuHawkWrapperFor { inherit bizhawkAssemblies ; hawkSourceInfo = hawkSourceInfoDev ; } ;
emuhawkWrapperScriptNonNixOS = ( wrapperScriptsFor { inherit bizhawkAssemblies ; hawkSourceInfo = hawkSourceInfoDev ; } ) . wrapperScriptNonNixOS ;
2021-11-18 12:39:15 +00:00
mono = monoFinal ;
2021-11-15 08:17:16 +00:00
}