setup nix source formatter

This commit is contained in:
Wolfgang Thaller 2023-12-28 23:50:29 +01:00
parent 09e4e34c41
commit b6b30d2c10
5 changed files with 189 additions and 165 deletions

View File

@ -1,9 +1,12 @@
let sources = import ./nix/sources.nix;
in { system ? builtins.currentSystem, nixpkgs ? sources.nixpkgs
, multiversal_src ? if builtins.pathExists ./multiversal/make-multiverse.rb then
./multiversal
else
sources.multiversal, ... }:
in { system ? builtins.currentSystem
, nixpkgs ? sources.nixpkgs
, multiversal_src ? if builtins.pathExists ./multiversal/make-multiverse.rb then
./multiversal
else
sources.multiversal
, ...
}:
let
retroPlatforms = import nix/platforms.nix;
@ -22,30 +25,36 @@ let
overlays = [ overlay ];
};
crossPkgs = lib.mapAttrs (name: plat:
import nixpkgs {
inherit system;
overlays = [ overlay ];
crossSystem = plat;
config = { allowUnsupportedSystem = true; };
}) retroPlatforms;
crossPkgs = lib.mapAttrs
(name: plat:
import nixpkgs {
inherit system;
overlays = [ overlay ];
crossSystem = plat;
config = { allowUnsupportedSystem = true; };
})
retroPlatforms;
targetPkgs = lib.mapAttrs (name: cross: cross.buildPackages) crossPkgs;
shell = lib.mapAttrs (name: cross:
cross.mkShell {
nativeBuildInputs = with overlaidPkgs; [
retro68.hfsutils
retro68.tools
cmake
gnumake
];
buildInputs = [ cross.retro68.console ];
} // cross) crossPkgs;
shell = lib.mapAttrs
(name: cross:
cross.mkShell
{
nativeBuildInputs = with overlaidPkgs; [
retro68.hfsutils
retro68.tools
cmake
gnumake
];
buildInputs = [ cross.retro68.console ];
} // cross)
crossPkgs;
in builtins.trace
"Warning: Retro68's default.nix is deprecated and will disappear soon. Please use the flake instead."
(shell.m68k // shell // {
inherit overlay;
inherit (overlaidPkgs) retro68;
targetPkg = targetPkgs;
})
in
builtins.trace
"Warning: Retro68's default.nix is deprecated and will disappear soon. Please use the flake instead."
(shell.m68k // shell // {
inherit overlay;
inherit (overlaidPkgs) retro68;
targetPkg = targetPkgs;
})

View File

@ -18,6 +18,8 @@
{
_module.args.pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
formatter = pkgs.nixpkgs-fmt;
legacyPackages.pkgsCross = lib.mapAttrs
(name: plat:
import nixpkgs {
@ -52,7 +54,7 @@
tools = pkgs.retro68.tools;
hfsutils = pkgs.retro68.hfsutils;
default = pkgs.runCommand "Retro68" {} ''
default = pkgs.runCommand "Retro68" { } ''
mkdir $out
mkdir $out/m68k-apple-macos
mkdir $out/powerpc-apple-macos
@ -86,7 +88,8 @@
overlays.default =
lib.composeManyExtensions [
((import nix/overlay.nix) {
multiversal_src = if builtins.pathExists ./multiversal/make-multiverse.rb
multiversal_src =
if builtins.pathExists ./multiversal/make-multiverse.rb
then ./multiversal
else multiversal;
})

View File

@ -10,7 +10,7 @@ pkgs: prevPkgs: {
src = ../.;
nativeBuildInputs = [ cmake bison flex ruby ninja bash ];
buildInputs = [ boost gmp mpfr libmpc zlib ]
++ lib.optional hostPlatform.isDarwin
++ lib.optional hostPlatform.isDarwin
darwin.apple_sdk.frameworks.ApplicationServices;
buildCommand = ''
bash $src/build-toolchain.bash --ninja --prefix=$out --no-carbon
@ -56,7 +56,7 @@ pkgs: prevPkgs: {
nativeBuildInputs = [ cmake bison flex ];
buildInputs = [ boost zlib retro68.hfsutils ]
++ lib.optional hostPlatform.isDarwin
++ lib.optional hostPlatform.isDarwin
darwin.apple_sdk.frameworks.ApplicationServices;
};
@ -75,15 +75,17 @@ pkgs: prevPkgs: {
++ stdenv.targetPlatform.retro68BinutilsConfig or [ ];
enableParallelBuilding = true;
postInstall = let
ld = "$out/bin/${stdenv.targetPlatform.config}-ld";
ld_real = "$out/bin/${stdenv.targetPlatform.config}-ld.real";
postInstall =
let
ld = "$out/bin/${stdenv.targetPlatform.config}-ld";
ld_real = "$out/bin/${stdenv.targetPlatform.config}-ld.real";
in ''
mv ${ld} ${ld_real}
in
''
mv ${ld} ${ld_real}
echo "#!${stdenv.shell}" > ${ld}
echo "exec \$'' + ''
echo "#!${stdenv.shell}" > ${ld}
echo "exec \$'' + ''
{RETRO68_LD_WRAPPER_${stdenv.targetPlatform.cmakeSystemName}-${ld_real}} \"\$@\"" >> ${ld}
chmod +x ${ld}
@ -117,7 +119,7 @@ pkgs: prevPkgs: {
make -j$NIX_BUILD_CORES
make install
'';
env.CXXFLAGS="--std=c++14"; # gcc 9 doesn't seem to like C++17
env.CXXFLAGS = "--std=c++14"; # gcc 9 doesn't seem to like C++17
};
# binutils -- binutils with the wrappers provided by nixpkgs
@ -147,54 +149,56 @@ pkgs: prevPkgs: {
} // prevPkgs.lib.optionalAttrs (prevPkgs.hostPlatform ? retro68) {
setup_hook = let
systemName = pkgs.targetPlatform.cmakeSystemName;
toolchain = pkgs.writeTextFile {
name = "retro68.cmake-toolchain";
text = ''
set(CMAKE_SYSTEM_NAME ${systemName})
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_CROSSCOMPILING TRUE)
setup_hook =
let
systemName = pkgs.targetPlatform.cmakeSystemName;
toolchain = pkgs.writeTextFile {
name = "retro68.cmake-toolchain";
text = ''
set(CMAKE_SYSTEM_NAME ${systemName})
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_CROSSCOMPILING TRUE)
set(REZ "${pkgs.buildPackages.retro68.tools}/bin/Rez" )
set(REZ_TEMPLATES_PATH ${pkgs.retro68.libretro}/RIncludes)
set(REZ "${pkgs.buildPackages.retro68.tools}/bin/Rez" )
set(REZ_TEMPLATES_PATH ${pkgs.retro68.libretro}/RIncludes)
set(MAKE_PEF "${pkgs.buildPackages.retro68.tools}/bin/MakePEF" )
set(MAKE_PEF "${pkgs.buildPackages.retro68.tools}/bin/MakePEF" )
include(${../cmake/add_application.cmake})
'' + (pkgs.lib.optionalString (systemName == "RetroCarbon") ''
set(CMAKE_EXE_LINKER_FLAGS_INIT "-carbon")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-carbon")
add_definitions( -DTARGET_API_MAC_CARBON=1 )
'');
};
hook = pkgs.writeTextFile {
name = "retro68.setup_hook";
text = ''
export CMAKE_TOOLCHAIN_FILE=${toolchain}
include(${../cmake/add_application.cmake})
'' + (pkgs.lib.optionalString (systemName == "RetroCarbon") ''
set(CMAKE_EXE_LINKER_FLAGS_INIT "-carbon")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-carbon")
add_definitions( -DTARGET_API_MAC_CARBON=1 )
'');
};
hook = pkgs.writeTextFile {
name = "retro68.setup_hook";
text = ''
export CMAKE_TOOLCHAIN_FILE=${toolchain}
retro68_addRIncludes() {
case $depHostOffset in
-1) local role='BUILD_' ;;
0) local role="" ;;
1) local role='TARGET_' ;;
*) echo "retro68_addRIncludes: Error: Cannot be used with $depHostOffset-offset deps" >2;
return 1 ;;
esac
retro68_addRIncludes() {
case $depHostOffset in
-1) local role='BUILD_' ;;
0) local role="" ;;
1) local role='TARGET_' ;;
*) echo "retro68_addRIncludes: Error: Cannot be used with $depHostOffset-offset deps" >2;
return 1 ;;
esac
if [[ -d "$1/RIncludes" ]]; then
export REZ_INCLUDE_PATH+=":$1/RIncludes"
fi
}
if [[ -d "$1/RIncludes" ]]; then
export REZ_INCLUDE_PATH+=":$1/RIncludes"
fi
}
addEnvHooks "$targetOffset" retro68_addRIncludes
addEnvHooks "$targetOffset" retro68_addRIncludes
'' + (pkgs.lib.optionalString (systemName == "Retro68") ''
export RETRO68_LD_WRAPPER_Retro68="${pkgs.buildPackages.retro68.tools}/bin/Elf2Mac"
export RETRO68_REAL_LD="${pkgs.buildPackages.retro68.binutils_unwrapped}/bin/m68k-apple-macos-ld.real"
'');
};
in pkgs.makeSetupHook { name = "retro68.setup_hook"; } hook;
'' + (pkgs.lib.optionalString (systemName == "Retro68") ''
export RETRO68_LD_WRAPPER_Retro68="${pkgs.buildPackages.retro68.tools}/bin/Elf2Mac"
export RETRO68_REAL_LD="${pkgs.buildPackages.retro68.binutils_unwrapped}/bin/m68k-apple-macos-ld.real"
'');
};
in
pkgs.makeSetupHook { name = "retro68.setup_hook"; } hook;
# ----------- Retro68 core libraries -------------
@ -221,14 +225,15 @@ pkgs: prevPkgs: {
import_libraries = with pkgs;
if stdenvNoCC.targetPlatform.system != "m68k-macos" then
stdenvNoCC.mkDerivation {
name = "retro68.import_libraries";
src = ../ImportLibraries;
buildCommand = ''
mkdir -p $out/lib
cp $src/*.a $out/lib/
'';
}
stdenvNoCC.mkDerivation
{
name = "retro68.import_libraries";
src = ../ImportLibraries;
buildCommand = ''
mkdir -p $out/lib
cp $src/*.a $out/lib/
'';
}
else
null;
@ -243,7 +248,8 @@ pkgs: prevPkgs: {
set(CMAKE_CROSSCOMPILING TRUE)
'';
};
in (pkgs.stdenv.override {
in
(pkgs.stdenv.override {
cc = stdenv.cc.override { extraPackages = [ ]; };
}).mkDerivation {
name = "libretro";
@ -279,14 +285,16 @@ pkgs: prevPkgs: {
# binutils -- binutils with the wrappers provided by nixpkgs
# note: on nix/darwin (as of nixpkgs 23.11), nixpkgs seems to
# ignore (or re-override) this override.
binutils = if (prevPkgs.targetPlatform ? retro68) then
pkgs.retro68.binutils
else
prevPkgs.binutils;
binutils =
if (prevPkgs.targetPlatform ? retro68) then
pkgs.retro68.binutils
else
prevPkgs.binutils;
# gcc -- gcc with the wrappers provided by nixpkgs
gcc = if (prevPkgs.targetPlatform ? retro68) then
pkgs.retro68.gcc
else
prevPkgs.gcc;
gcc =
if (prevPkgs.targetPlatform ? retro68) then
pkgs.retro68.gcc
else
prevPkgs.gcc;
}

View File

@ -2,18 +2,20 @@ pkgs: prevPkgs: {
retro68 = prevPkgs.retro68.overrideScope' (self: prevRetro: {
samples = with pkgs;
let
individualSamples = lib.mapAttrs (key: path:
stdenv.mkDerivation {
name = "retro68.samples." + key;
src = path;
nativeBuildInputs = [ buildPackages.ninja buildPackages.cmake ];
buildInputs = [ retro68.console ];
installPhase = ''
mkdir $out
cp *.bin $out/
rm -f $out/*.code.bin $out/*.rsrc.bin
'';
}) ({
individualSamples = lib.mapAttrs
(key: path:
stdenv.mkDerivation {
name = "retro68.samples." + key;
src = path;
nativeBuildInputs = [ buildPackages.ninja buildPackages.cmake ];
buildInputs = [ retro68.console ];
installPhase = ''
mkdir $out
cp *.bin $out/
rm -f $out/*.code.bin $out/*.rsrc.bin
'';
})
({
dialog = ../Samples/Dialog;
helloworld = ../Samples/HelloWorld;
raytracer = ../Samples/Raytracer;
@ -25,8 +27,9 @@ pkgs: prevPkgs: {
} // lib.optionalAttrs (targetPlatform.cmakeSystemName == "Retro68") {
systemextension = ../Samples/SystemExtension;
launcher = ../Samples/Launcher;
}) // { launchapplserver = self.launchapplserver; };
in runCommand "retro68.samples" { } ''
}) // { launchapplserver = self.launchapplserver; };
in
runCommand "retro68.samples" { } ''
mkdir -p $out/
${lib.concatMapStrings (x: ''

View File

@ -1,58 +1,59 @@
pkgs: prevPkgs:
{
retro68 = if !(prevPkgs.hostPlatform ? retro68) then
prevPkgs.retro68
else
prevPkgs.retro68.overrideScope' (self: prevRetro: {
retro68 =
if !(prevPkgs.hostPlatform ? retro68) then
prevPkgs.retro68
else
prevPkgs.retro68.overrideScope' (self: prevRetro: {
mpw_35_gm = with pkgs;
fetchurl {
url =
"https://web.archive.org/web/20210309154524/https://staticky.com/mirrors/ftp.apple.com/developer/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./MPW-GM_Images/MPW-GM.img.bin";
sha256 = "0wm8dwmm0cpp8px27in564ih27sn5vbydz3jqpzwh04qpfazmfwr";
};
mpw_35_gm = with pkgs;
fetchurl {
url =
"https://web.archive.org/web/20210309154524/https://staticky.com/mirrors/ftp.apple.com/developer/Tool_Chest/Core_Mac_OS_Tools/MPW_etc./MPW-GM_Images/MPW-GM.img.bin";
sha256 = "0wm8dwmm0cpp8px27in564ih27sn5vbydz3jqpzwh04qpfazmfwr";
};
universal = with pkgs;
stdenvNoCC.mkDerivation {
name = "retro68.universal";
src = retro68.mpw_35_gm;
nativeBuildInputs = with buildPackages.retro68; [
tools
hfsutils
binutils_unwrapped
];
universal = with pkgs;
stdenvNoCC.mkDerivation {
name = "retro68.universal";
src = retro68.mpw_35_gm;
nativeBuildInputs = with buildPackages.retro68; [
tools
hfsutils
binutils_unwrapped
];
buildCommand = ''
ConvertDiskImage $src decoded.dsk
export HOME=.
hmount decoded.dsk
mkdir -p CIncludes RIncludes
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:CIncludes:*.h' CIncludes/
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:RIncludes:*.r' RIncludes/
mkdir -p $out/include $out/RIncludes
bash ${../prepare-headers.sh} CIncludes $out/include
bash ${../prepare-rincludes.sh} RIncludes $out/RIncludes
buildCommand = ''
ConvertDiskImage $src decoded.dsk
export HOME=.
hmount decoded.dsk
mkdir -p CIncludes RIncludes
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:CIncludes:*.h' CIncludes/
hcopy -t 'MPW-GM:MPW-GM:Interfaces&Libraries:Interfaces:RIncludes:*.r' RIncludes/
mkdir -p $out/include $out/RIncludes
bash ${../prepare-headers.sh} CIncludes $out/include
bash ${../prepare-rincludes.sh} RIncludes $out/RIncludes
. ${../interfaces-and-libraries.sh}
'' + (pkgs.lib.optionalString (pkgs.targetPlatform.cmakeSystemName == "Retro68") ''
mkdir -p lib68
hcopy -r 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:Libraries:*.o' lib68
M68KLIBRARIES=lib68
setup68KLibraries $out/
mv $out/lib68k $out/lib
'') + (pkgs.lib.optionalString (pkgs.targetPlatform.cmakeSystemName != "Retro68") ''
mkdir -p libppc peflibs
hcopy -r 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:PPCLibraries:*.o' libppc
hcopy -m 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:SharedLibraries:*' peflibs
PPCLIBRARIES=libppc
SHAREDLIBRARIES=peflibs
INTERFACELIB=peflibs/InterfaceLib.bin
. ${../interfaces-and-libraries.sh}
'' + (pkgs.lib.optionalString (pkgs.targetPlatform.cmakeSystemName == "Retro68") ''
mkdir -p lib68
hcopy -r 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:Libraries:*.o' lib68
M68KLIBRARIES=lib68
setup68KLibraries $out/
mv $out/lib68k $out/lib
'') + (pkgs.lib.optionalString (pkgs.targetPlatform.cmakeSystemName != "Retro68") ''
mkdir -p libppc peflibs
hcopy -r 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:PPCLibraries:*.o' libppc
hcopy -m 'MPW-GM:MPW-GM:Interfaces&Libraries:Libraries:SharedLibraries:*' peflibs
PPCLIBRARIES=libppc
SHAREDLIBRARIES=peflibs
INTERFACELIB=peflibs/InterfaceLib.bin
setupPPCLibraries $out/
mv $out/libppc $out/lib
'');
};
});
setupPPCLibraries $out/
mv $out/libppc $out/lib
'');
};
});
stdenvUniversal = pkgs.stdenv.override {
cc = pkgs.stdenv.cc.override {