From a67591e4a88d9974aa384f57a290a6dbc395d7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Wed, 4 Dec 2024 19:56:59 +0100 Subject: [PATCH 1/4] famistudio: nixfmt --- .../audio/famistudio/build-native-wrapper.nix | 97 ++++++---- .../applications/audio/famistudio/default.nix | 177 +++++++++++------- 2 files changed, 166 insertions(+), 108 deletions(-) diff --git a/pkgs/applications/audio/famistudio/build-native-wrapper.nix b/pkgs/applications/audio/famistudio/build-native-wrapper.nix index ddee5bf5712dc..6d986ff520d93 100644 --- a/pkgs/applications/audio/famistudio/build-native-wrapper.nix +++ b/pkgs/applications/audio/famistudio/build-native-wrapper.nix @@ -1,54 +1,69 @@ -{ depname -, version -, src -, sourceRoot -, stdenv -, lib -, patches ? [] -, extraPostPatch ? "" -, buildInputs ? [] +{ + depname, + version, + src, + sourceRoot, + stdenv, + lib, + patches ? [ ], + extraPostPatch ? "", + buildInputs ? [ ], }: let - rebuildscriptName = if stdenv.hostPlatform.isLinux then - "build_linux" - else if stdenv.hostPlatform.isDarwin then - "build_macos" - else throw "Don't know how to rebuild FamiStudio's vendored ${depname} for ${stdenv.hostPlatform.system}"; + rebuildscriptName = + if stdenv.hostPlatform.isLinux then + "build_linux" + else if stdenv.hostPlatform.isDarwin then + "build_macos" + else + throw "Don't know how to rebuild FamiStudio's vendored ${depname} for ${stdenv.hostPlatform.system}"; in stdenv.mkDerivation { pname = "famistudio-nativedep-${depname}"; - inherit version src sourceRoot patches buildInputs; + inherit + version + src + sourceRoot + patches + buildInputs + ; - postPatch = let - libnameBase = lib.optionalString stdenv.hostPlatform.isLinux "lib" + depname; - in '' - # Use one name for build script, eases with patching - mv ${rebuildscriptName}.sh build.sh + postPatch = + let + libnameBase = lib.optionalString stdenv.hostPlatform.isLinux "lib" + depname; + in + '' + # Use one name for build script, eases with patching + mv ${rebuildscriptName}.sh build.sh - # Scripts use hardcoded compilers and try to copy built libraries into FamiStudio's build tree - # Not all scripts use the same compiler, so don't fail on replacing that - substituteInPlace build.sh \ - --replace-fail '../../FamiStudio/' "$out/lib/" \ - --replace-quiet 'g++' "$CXX" + # Scripts use hardcoded compilers and try to copy built libraries into FamiStudio's build tree + # Not all scripts use the same compiler, so don't fail on replacing that + substituteInPlace build.sh \ + --replace-fail '../../FamiStudio/' "$out/lib/" \ + --replace-quiet 'g++' "$CXX" - # Replacing gcc via sed, would break -static-libgcc otherwise - sed -i -e "s/^gcc/$CC/g" build.sh - '' + lib.optionalString stdenv.hostPlatform.isDarwin '' - # Darwin rebuild scripts try to make a universal2 dylib - # - build dylib for non-hostPlatform - # - copy built library into special directory for later packaging script - # - join two dylibs together into a universal2 dylib - # Remove everything we don't need - sed -ri \ - -e '/-target ${if stdenv.hostPlatform.isx86_64 then "arm64" else "x86_64"}/d' \ - -e '/..\/..\/Setup/d' \ - build.sh + # Replacing gcc via sed, would break -static-libgcc otherwise + sed -i -e "s/^gcc/$CC/g" build.sh + '' + + lib.optionalString stdenv.hostPlatform.isDarwin '' + # Darwin rebuild scripts try to make a universal2 dylib + # - build dylib for non-hostPlatform + # - copy built library into special directory for later packaging script + # - join two dylibs together into a universal2 dylib + # Remove everything we don't need + sed -ri \ + -e '/-target ${if stdenv.hostPlatform.isx86_64 then "arm64" else "x86_64"}/d' \ + -e '/..\/..\/Setup/d' \ + build.sh - # Replace joining multi-arch dylibs with copying dylib for target arch - substituteInPlace build.sh \ - --replace-fail 'lipo -create -output ${libnameBase}.dylib' 'cp ${libnameBase}_${if stdenv.hostPlatform.isx86_64 then "x86_64" else "arm64"}.dylib ${libnameBase}.dylib #' - '' + extraPostPatch; + # Replace joining multi-arch dylibs with copying dylib for target arch + substituteInPlace build.sh \ + --replace-fail 'lipo -create -output ${libnameBase}.dylib' 'cp ${libnameBase}_${ + if stdenv.hostPlatform.isx86_64 then "x86_64" else "arm64" + }.dylib ${libnameBase}.dylib #' + '' + + extraPostPatch; dontConfigure = true; dontInstall = true; # rebuild script automatically installs diff --git a/pkgs/applications/audio/famistudio/default.nix b/pkgs/applications/audio/famistudio/default.nix index 4e13d1aa0a5fa..3cc85abfa054f 100644 --- a/pkgs/applications/audio/famistudio/default.nix +++ b/pkgs/applications/audio/famistudio/default.nix @@ -1,25 +1,28 @@ -{ stdenv -, lib -, buildDotnetModule -, dotnetCorePackages -, callPackage -, fetchFromGitHub -, ffmpeg -, glfw -, libglvnd -, libogg -, libvorbis -, openal -, portaudio -, rtmidi +{ + stdenv, + lib, + buildDotnetModule, + dotnetCorePackages, + callPackage, + fetchFromGitHub, + ffmpeg, + glfw, + libglvnd, + libogg, + libvorbis, + 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}"; + 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"; @@ -32,57 +35,97 @@ buildDotnetModule rec { 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*} + 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} + # 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} + # 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' - ''; + # 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; From b44f29245d180d7133cc45c510e566b6f89a27b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Wed, 4 Dec 2024 20:56:52 +0100 Subject: [PATCH 2/4] famistudio: migrate to by-name --- .../audio => by-name/fa}/famistudio/build-native-wrapper.nix | 0 pkgs/{applications/audio => by-name/fa}/famistudio/deps.nix | 0 .../default.nix => by-name/fa/famistudio/package.nix} | 0 pkgs/{applications/audio => by-name/fa}/famistudio/update.sh | 0 pkgs/top-level/all-packages.nix | 2 -- 5 files changed, 2 deletions(-) rename pkgs/{applications/audio => by-name/fa}/famistudio/build-native-wrapper.nix (100%) rename pkgs/{applications/audio => by-name/fa}/famistudio/deps.nix (100%) rename pkgs/{applications/audio/famistudio/default.nix => by-name/fa/famistudio/package.nix} (100%) rename pkgs/{applications/audio => by-name/fa}/famistudio/update.sh (100%) diff --git a/pkgs/applications/audio/famistudio/build-native-wrapper.nix b/pkgs/by-name/fa/famistudio/build-native-wrapper.nix similarity index 100% rename from pkgs/applications/audio/famistudio/build-native-wrapper.nix rename to pkgs/by-name/fa/famistudio/build-native-wrapper.nix diff --git a/pkgs/applications/audio/famistudio/deps.nix b/pkgs/by-name/fa/famistudio/deps.nix similarity index 100% rename from pkgs/applications/audio/famistudio/deps.nix rename to pkgs/by-name/fa/famistudio/deps.nix diff --git a/pkgs/applications/audio/famistudio/default.nix b/pkgs/by-name/fa/famistudio/package.nix similarity index 100% rename from pkgs/applications/audio/famistudio/default.nix rename to pkgs/by-name/fa/famistudio/package.nix diff --git a/pkgs/applications/audio/famistudio/update.sh b/pkgs/by-name/fa/famistudio/update.sh similarity index 100% rename from pkgs/applications/audio/famistudio/update.sh rename to pkgs/by-name/fa/famistudio/update.sh diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index bb4126e3f906c..ad2e6cbc8ee4c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13691,8 +13691,6 @@ with pkgs; evolution = callPackage ../applications/networking/mailreaders/evolution/evolution { }; evolutionWithPlugins = callPackage ../applications/networking/mailreaders/evolution/evolution/wrapper.nix { plugins = [ evolution evolution-ews ]; }; - famistudio = darwin.apple_sdk_11_0.callPackage ../applications/audio/famistudio { }; - fdr = libsForQt5.callPackage ../applications/science/programming/fdr { }; fetchmail = callPackage ../applications/misc/fetchmail { }; From 73363329ba9e7c4f9f950ba34d24df48cc05cb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Wed, 4 Dec 2024 21:13:13 +0100 Subject: [PATCH 3/4] famistudio: .NET 7 -> 8 --- pkgs/by-name/fa/famistudio/package.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/fa/famistudio/package.nix b/pkgs/by-name/fa/famistudio/package.nix index 3cc85abfa054f..8df5b3065ca38 100644 --- a/pkgs/by-name/fa/famistudio/package.nix +++ b/pkgs/by-name/fa/famistudio/package.nix @@ -129,8 +129,9 @@ buildDotnetModule rec { projectFile = "FamiStudio/${csprojName}.csproj"; nugetDeps = ./deps.nix; - dotnet-sdk = dotnetCorePackages.sdk_7_0; - dotnet-runtime = dotnetCorePackages.runtime_7_0; + dotnet-sdk = dotnetCorePackages.sdk_8_0; + dotnet-runtime = dotnetCorePackages.runtime_8_0; + dotnetFlags = [ "-p:TargetFramework=net8.0" ]; runtimeDeps = lib.optionals stdenv.hostPlatform.isLinux [ libglvnd From 6498028369ccd77451363e6a2b1dc6ba29c43bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gutyina=20Gerg=C5=91?= Date: Wed, 4 Dec 2024 21:14:15 +0100 Subject: [PATCH 4/4] famistudio: remove `with lib;` --- pkgs/by-name/fa/famistudio/package.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/fa/famistudio/package.nix b/pkgs/by-name/fa/famistudio/package.nix index 8df5b3065ca38..ff169cd2741ee 100644 --- a/pkgs/by-name/fa/famistudio/package.nix +++ b/pkgs/by-name/fa/famistudio/package.nix @@ -154,16 +154,18 @@ buildDotnetModule rec { passthru.updateScript = ./update.sh; - meta = with lib; { + meta = { 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; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ + OPNA2608 + ]; + platforms = lib.platforms.unix; mainProgram = "FamiStudio"; }; }