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
|
{ stdenv
, lib
, buildDotnetModule
, dotnetCorePackages
, callPackage
, fetchFromGitHub
, ffmpeg
, glfw
, libglvnd
, libogg
, libvorbis
, makeWrapper
, openal
, portaudio
, rtmidi
}:
let
csprojName = if stdenv.hostPlatform.isLinux then
"FamiStudio.Linux"
else if stdenv.hostPlatform.isDarwin then
"FamiStudio.Mac"
else throw "Don't know how to build FamiStudio for ${stdenv.hostPlatform.system}";
in
buildDotnetModule rec {
pname = "famistudio";
version = "4.2.1";
src = fetchFromGitHub {
owner = "BleuBleu";
repo = "FamiStudio";
rev = "refs/tags/${version}";
hash = "sha256-WYy/6cWQg3Ayok/eAdnvlWAvdcuhy/sdlWOVvaYcPkc=";
};
postPatch = let
libname = library: "${library}${stdenv.hostPlatform.extensions.sharedLibrary}";
buildNativeWrapper = args: callPackage ./build-native-wrapper.nix (args // {
inherit version src;
sourceRoot = "${src.name}/ThirdParty/${args.depname}";
});
nativeWrapperToReplaceFormat = args: let
libPrefix = lib.optionalString stdenv.hostPlatform.isLinux "lib";
in {
package = buildNativeWrapper args;
expectedName = "${libPrefix}${args.depname}";
ourName = "${libPrefix}${args.depname}";
};
librariesToReplace = [
# Unmodified native libraries that we can fully substitute
{ package = glfw; expectedName = "libglfw"; ourName = "libglfw"; }
{ package = rtmidi; expectedName = "librtmidi"; ourName = "librtmidi"; }
] ++ lib.optionals stdenv.hostPlatform.isLinux [
{ package = openal; expectedName = "libopenal32"; ourName = "libopenal"; }
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
{ package = portaudio; expectedName = "libportaudio.2"; ourName = "libportaudio.2"; }
] ++ [
# Native libraries, with extra code for the C# wrapping
(nativeWrapperToReplaceFormat { depname = "GifDec"; })
(nativeWrapperToReplaceFormat { depname = "NesSndEmu"; })
(nativeWrapperToReplaceFormat { depname = "NotSoFatso"; extraPostPatch = ''
# C++17 does not allow register storage class specifier
substituteInPlace build.sh \
--replace-fail "$CXX" "$CXX -std=c++14"
''; })
(nativeWrapperToReplaceFormat { depname = "ShineMp3"; })
(nativeWrapperToReplaceFormat { depname = "Stb"; })
(nativeWrapperToReplaceFormat { depname = "Vorbis"; buildInputs = [ libogg libvorbis ]; })
];
libraryReplaceArgs = lib.strings.concatMapStringsSep " "
(library: "--replace-fail '${libname library.expectedName}' '${lib.getLib library.package}/lib/${libname library.ourName}'")
librariesToReplace;
in ''
# Don't use any prebuilt libraries
rm FamiStudio/*.{dll,dylib,so*}
# Replace copying of vendored prebuilt native libraries with copying of our native libraries
substituteInPlace ${projectFile} ${libraryReplaceArgs}
# Un-hardcode target platform if set
sed -i -e '/PlatformTarget/d' ${projectFile}
# Don't require a special name to be preserved, our OpenAL isn't 32-bit
substituteInPlace FamiStudio/Source/AudioStreams/OpenALStream.cs \
--replace-fail 'libopenal32' 'libopenal'
'';
projectFile = "FamiStudio/${csprojName}.csproj";
nugetDeps = ./deps.nix;
dotnet-sdk = dotnetCorePackages.sdk_7_0;
dotnet-runtime = dotnetCorePackages.runtime_7_0;
runtimeDeps = lib.optionals stdenv.hostPlatform.isLinux [
libglvnd
];
executables = [ "FamiStudio" ];
postInstall = ''
mkdir -p $out/share/famistudio
for datdir in Setup/Demo\ {Instruments,Songs}; do
cp -R "$datdir" $out/share/famistudio/
done
'';
postFixup = ''
# FFMpeg looked up from PATH
wrapProgram $out/bin/FamiStudio \
--prefix PATH : ${lib.makeBinPath [ ffmpeg ]}
'';
passthru.updateScript = ./update.sh;
meta = with lib; {
homepage = "https://famistudio.org/";
description = "NES Music Editor";
longDescription = ''
FamiStudio is very simple music editor for the Nintendo Entertainment System
or Famicom. It is targeted at both chiptune artists and NES homebrewers.
'';
license = licenses.mit;
maintainers = with maintainers; [ OPNA2608 ];
platforms = platforms.unix;
mainProgram = "FamiStudio";
};
}
|