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
, useCWDAsSource ? false
2021-12-08 17:02:46 +00:00
, hawkSourceInfo ? if useCWDAsSource
then rec {
version = " 2 . 7 . 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}/"`)
drv = builtins . path {
path = ./. ;
name = " B i z H a w k - ${ version } " ;
filter = let # this is just for speed, not any r13y concern
2021-12-13 09:47:21 +00:00
denyList = [ " . g i t " " . i d e a " " E x t e r n a l C o r e P r o j e c t s " " E x t e r n a l P r o j e c t s " " E x t e r n a l T o o l P r o j e c t s " " l i b H a w k " " l i b m u p e n 6 4 p l u s " " L i b r e t r o B r i d g e " " L u a I n t e r f a c e " " l y n x " " p s x " " q u i c k n e s " " s u b m o d u l e s " " w a t e r b o x " " w o n d e r s w a n " ] ;
2021-12-08 17:02:46 +00:00
in path : type : type == " r e g u l a r " || ( type == " d i r e c t o r y " && ! builtins . elem ( baseNameOf path ) denyList ) ;
} ;
2021-11-15 08:17:16 +00:00
}
2021-12-08 17:02:46 +00:00
else {
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 = " ;
} ;
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
, p7zip ? pkgs . p7zip
# 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
2021-11-15 08:17:16 +00:00
bizhawk = buildDotnetModule rec {
pname = " B i z H a w k " ;
2021-12-08 17:02:46 +00:00
version = hawkSourceInfo . version ;
src = hawkSourceInfo . drv ;
2021-12-01 06:31:53 +00:00
dotnet-sdk = if useCWDAsSource then dotnet-sdk_6 else dotnet-sdk_5 ;
2021-12-08 17:02:46 +00:00
nativeBuildInputs = [ p7zip ] ;
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 " ;
2021-12-01 06:31:53 +00:00
nugetDeps = if useCWDAsSource then Dist/deps.nix else Dist/deps-old.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-11-15 08:17:16 +00:00
buildPhase = ''
2021-11-18 12:39:15 +00:00
$ { commentUnless useCWDAsSource } cd src/BizHawk.Version
$ { commentUnless useCWDAsSource } dotnet build $ { extraDotnetBuildFlags }
$ { commentUnless useCWDAsSource } cd ../..
2021-11-15 08:17:16 +00:00
Dist/Build $ { buildConfig } . sh $ { extraDotnetBuildFlags }
printf " N i x " > output/dll/custombuild.txt
Dist/Package.sh linux-x64
rm packaged_output/EmuHawkMono.sh # replaced w/ below script(s)
'' ;
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 = ''
mkdir - p $ out
cp - aTv packaged_output $ out
'' ;
dontPatchELF = true ;
} ;
2021-12-02 05:41:15 +00:00
wrapperScripts = import Dist/wrapper-scripts.nix {
inherit ( pkgs ) lib writeShellScriptBin writeText ;
2021-12-08 17:02:46 +00:00
inherit commentUnless versionAtLeast mesa openal debugPInvokes initConfig ;
hawkVersion = hawkSourceInfo . version ;
2021-12-02 05:41:15 +00:00
mono = monoFinal ;
} ;
2021-11-18 12:39:15 +00:00
in {
bizhawkAssemblies = bizhawk ;
emuhawk = stdenv . mkDerivation rec {
pname = " e m u h a w k - m o n o r t " ;
2021-12-08 17:02:46 +00:00
version = hawkSourceInfo . version ;
2021-11-18 12:39:15 +00:00
nativeBuildInputs = [ makeWrapper ] ;
buildInputs = [ bizhawk ] ;
# there must be a helper for this somewhere...
dontUnpack = true ;
dontPatch = true ;
dontConfigure = true ;
dontBuild = true ;
installPhase = ''
mkdir - p $ out/bin
2021-12-02 05:41:15 +00:00
makeWrapper $ { 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 " } $ out/bin / $ { pname } - $ { version } \
2021-11-18 12:39:15 +00:00
- - set BIZHAWK_HOME $ { bizhawk }
'' ;
dontFixup = true ;
# desktopItems = [ (makeDesktopItem rec {
# name = "emuhawk-monort-${version}"; # actually filename
# exec = "${pname}-monort-${version}";
# desktopName = "EmuHawk (Mono Runtime)"; # actually Name
# }) ];
} ;
2021-12-02 05:41:15 +00:00
emuhawkWrapperScriptNonNixOS = wrapperScripts . wrapperScriptNonNixOS ;
2021-11-18 12:39:15 +00:00
mono = monoFinal ;
2021-11-15 08:17:16 +00:00
}