forked from TASEmulators/BizHawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
169 lines (169 loc) · 7.58 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/23.11.tar.gz") {}
, lib ? pkgs.lib
, stdenv ? pkgs.stdenvNoCC
# infrastructure
, buildDotnetModule ? pkgs.buildDotnetModule
, dpkg ? pkgs.dpkg
, fetchFromGitHub ? pkgs.fetchFromGitHub
, fetchFromGitLab ? pkgs.fetchFromGitLab
, fetchpatch ? pkgs.fetchpatch
, fetchzip ? pkgs.fetchzip
, makeDesktopItem ? pkgs.makeDesktopItem
, mkNugetDeps ? pkgs.mkNugetDeps
, runCommand ? pkgs.runCommand
, symlinkJoin ? pkgs.symlinkJoin
, writeShellScript ? pkgs.writeShellScript
, writeShellScriptBin ? pkgs.writeShellScriptBin
, writeText ? pkgs.writeText
# source
, hawkSourceInfoDevBuild ? let # called "dev build", but you could pass whatever branch and commit you want here
version = "2.9.2-local"; # used in default value of `BIZHAWK_DATA_HOME`, which distinguishes parallel installs' config and other data
in {
inherit version;
src = builtins.path { path = ./.; name = "BizHawk-${version}"; }; # source derivation; 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
}
# makedeps
, dotnet-sdk_8 ? pkgs.dotnet-sdk_8
, dotnet-sdk_6 ? pkgs.dotnet-sdk_6
, dotnet-sdk_5 ? let result = builtins.tryEval pkgs.dotnet-sdk_5; in if result.success
then result.value
else (import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/5234f4ce9340fffb705b908fff4896faeddb8a12^.tar.gz") {}).dotnet-sdk_5
, git ? pkgs.gitMinimal # only when building from-CWD (`-local`)
# rundeps
, coreutils ? pkgs.coreutils
, libgdiplus ? pkgs.libgdiplus
, libGL ? pkgs.libGL
, lua ? pkgs.lua54Packages.lua
, mono ? null
, nixGLChannel ? (pkgs.nixgl or import (fetchTarball "https://github.com/guibou/nixGL/archive/489d6b095ab9d289fe11af0219a9ff00fe87c7c5.tar.gz") {})
, nixGL ? nixGLChannel.auto.nixGLDefault
#, nixVulkan ? nixGLChannel.auto.nixVulkanNvidia
, openal ? pkgs.openal
, SDL2 ? pkgs.SDL2
, udev ? pkgs.udev
, zstd ? pkgs.zstd
# other parameters
, buildConfig ? "Release" # "Debug"/"Release"
, debugPInvokes ? false # forwarded to Dist/launch-scripts.nix
, debugDotnetHostCrashes ? false # forwarded to Dist/launch-scripts.nix
, doCheck ? true # runs `Dist/BuildTest${buildConfig}.sh`
, emuhawkBuildFlavour ? "NixHawk"
, extraDefines ? "" # added to `<DefineConstants/>`, so ';'-separated
, extraDotnetBuildFlags ? "" # currently passed to EVERY `dotnet build` and `dotnet test` invocation (and does not replace the flags for parallel compilation added by default)
, forNixOS ? true
, initConfig ? {} # forwarded to Dist/launch-scripts.nix (see docs there)
}: let
isVersionAtLeast = lib.flip lib.versionAtLeast; # I stand by this being the more useful param order w.r.t. currying
replaceDotWithUnderscore = s: lib.replaceStrings [ "." ] [ "_" ] s;
/** you can't actually make hard links in the sandbox, so this just copies, and we'll rely on Nix' automatic deduping */
hardLinkJoin =
{ name
, paths
, preferLocalBuild ? true
, allowSubstitutes ? false
, __contentAddressed ? false
}: runCommand name {
inherit __contentAddressed allowSubstitutes paths preferLocalBuild;
passAsFile = [ "paths" ];
} ''
mkdir -p $out
for d in $(cat $pathsPath); do
cd "$d"
find . -type d -exec mkdir -p "$out/{}" \;
for f in $(find . -type f); do cp -T "$(realpath "$f")" "$out/$f"; done
done
'';
inherit (import Dist/historical.nix {
inherit lib
isVersionAtLeast replaceDotWithUnderscore
fetchFromGitHub fetchFromGitLab mkNugetDeps
dotnet-sdk_5 dotnet-sdk_6 dotnet-sdk_8;
}) depsForHistoricalRelease populateHawkSourceInfo releaseArtifactInfos releaseFrags releaseTagSourceInfos;
launchScriptsFor = bizhawkAssemblies: isManualLocalBuild: import Dist/launch-scripts.nix {
inherit lib
writeShellScript writeText
bizhawkAssemblies nixGL
debugPInvokes debugDotnetHostCrashes initConfig isManualLocalBuild;
mkfifo = coreutils;
mktemp = coreutils;
};
pp = import Dist/packages.nix {
inherit lib stdenv
populateHawkSourceInfo replaceDotWithUnderscore
buildDotnetModule fetchpatch fetchzip hardLinkJoin launchScriptsFor makeDesktopItem
releaseTagSourceInfos runCommand symlinkJoin writeShellScriptBin
git
libgdiplus libGL lua openal SDL2 udev zstd
buildConfig doCheck emuhawkBuildFlavour extraDefines extraDotnetBuildFlags;
mono = if mono != null
then mono # allow older Mono if set explicitly
else if isVersionAtLeast "6.12.0.151" pkgs.mono.version
then pkgs.mono
else lib.trace "provided Mono too old, using Mono from Nixpkgs 23.05"
(import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/23.05.tar.gz") {}).mono;
monoBasic = fetchzip {
url = "https://download.mono-project.com/repo/debian/pool/main/m/mono-basic/libmono-microsoft-visualbasic10.0-cil_4.7-0xamarin3+debian9b1_all.deb";
nativeBuildInputs = [ dpkg ];
hash = "sha256-2m1FwpDxzqVXR6GUB3oFuTqIXCde/msb+tg8v6lIN6s=";
# tried and failed building from source, following https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=mono-basic
};
};
emuhawk-local = pp.buildEmuHawkInstallableFor {
inherit forNixOS;
hawkSourceInfo = hawkSourceInfoDevBuild;
};
fillTargetOSDifferences = hawkSourceInfo: lib.optionalAttrs forNixOS { needsLibGLVND = true; } // hawkSourceInfo; # don't like this, but the alternative is including `forNixOS` in `hawkSourceInfo` directly
asmsFromReleaseArtifacts = lib.mapAttrs
(_: a: pp.splitReleaseArtifact (a // { hawkSourceInfo = fillTargetOSDifferences a.hawkSourceInfo; }))
releaseArtifactInfos;
# the asms for from-CWD and latest release from-source are exposed below as `bizhawkAssemblies` and `bizhawkAssemblies-latest`, respectively
# apart from that, no `asmsFromSource`, since if you're only after the assets you might as well use the release artifact
releasesEmuHawkInstallables = lib.pipe releaseFrags [
(builtins.map (versionFrag: [
({
name = "emuhawk-${versionFrag}";
value = pp.buildEmuHawkInstallableFor {
inherit forNixOS;
hawkSourceInfo = releaseTagSourceInfos."info-${versionFrag}";
};
})
({
name = "emuhawk-${versionFrag}-bin";
value = pp.buildEmuHawkInstallableFor {
inherit forNixOS;
bizhawkAssemblies = asmsFromReleaseArtifacts."bizhawkAssemblies-${versionFrag}-bin";
};
})
]))
lib.concatLists
lib.listToAttrs
(lib.filterAttrs (name: value: lib.hasSuffix "-bin" name
|| isVersionAtLeast "2.6" value.hawkSourceInfo.version))
];
latestVersionFrag = lib.head releaseFrags;
combined = pp // asmsFromReleaseArtifacts // releasesEmuHawkInstallables // {
inherit depsForHistoricalRelease releaseTagSourceInfos;
bizhawkAssemblies = pp.buildAssembliesFor (fillTargetOSDifferences hawkSourceInfoDevBuild);
"bizhawkAssemblies-${latestVersionFrag}" = pp.buildAssembliesFor
(fillTargetOSDifferences releaseTagSourceInfos."info-${latestVersionFrag}");
discohawk = pp.buildDiscoHawkInstallableFor {
inherit forNixOS;
hawkSourceInfo = hawkSourceInfoDevBuild;
};
"discohawk-${latestVersionFrag}" = pp.buildDiscoHawkInstallableFor {
inherit forNixOS;
hawkSourceInfo = releaseTagSourceInfos."info-${latestVersionFrag}";
};
"discohawk-${latestVersionFrag}-bin" = pp.buildDiscoHawkInstallableFor {
inherit forNixOS;
bizhawkAssemblies = asmsFromReleaseArtifacts."bizhawkAssemblies-${latestVersionFrag}-bin";
};
emuhawk = emuhawk-local;
launchScriptsForLocalBuild = launchScriptsFor emuhawk-local.assemblies true;
};
in combined // lib.listToAttrs (lib.concatLists (builtins.map
(f: [
{ name = f "latest-bin"; value = combined.${f "${latestVersionFrag}-bin"}; }
{ name = f "latest"; value = combined.${f latestVersionFrag}; }
])
[ (s: "bizhawkAssemblies-${s}") (s: "emuhawk-${s}") (s: "discohawk-${s}") ]))