nim-1_0: move to pkgs/by-name from nim1

This commit is contained in:
Emery Hemingway 2024-10-27 19:30:22 +00:00
parent 68347d5542
commit 9c7030ae57
4 changed files with 13 additions and 147 deletions

View File

@ -0,0 +1,12 @@
{
lib,
stdenv,
fetchurl,
nim-unwrapped-1,
nim,
}:
nim.passthru.wrapNim {
nimUnwrapped = nim-unwrapped-1;
patches = [ ./nim.cfg.patch ];
}

View File

@ -1,143 +0,0 @@
# https://nim-lang.github.io/Nim/packaging.html
# https://nim-lang.org/docs/nimc.html
{ lib, callPackage, buildPackages, stdenv
, makeWrapper, openssl, pcre, Security
, nim-unwrapped-1 }:
let
inherit (nim-unwrapped-1.passthru) nimHost nimTarget;
wrapNim = { nim', patches }:
let targetPlatformConfig = stdenv.targetPlatform.config;
in stdenv.mkDerivation (finalAttrs: {
name = "${targetPlatformConfig}-nim-wrapper-${nim'.version}";
inherit (nim') version;
preferLocalBuild = true;
strictDeps = true;
nativeBuildInputs = [ makeWrapper ];
# Needed for any nim package that uses the standard library's
# 'std/sysrand' module.
depsTargetTargetPropagated = lib.optional stdenv.hostPlatform.isDarwin Security;
inherit patches;
unpackPhase = ''
runHook preUnpack
tar xf ${nim'.src} nim-$version/config
cd nim-$version
runHook postUnpack
'';
dontConfigure = true;
buildPhase =
# Configure the Nim compiler to use $CC and $CXX as backends
# The compiler is configured by two configuration files, each with
# a different DSL. The order of evaluation matters and that order
# is not documented, so duplicate the configuration across both files.
''
runHook preBuild
cat >> config/config.nims << WTF
switch("os", "${nimTarget.os}")
switch("cpu", "${nimTarget.cpu}")
switch("define", "nixbuild")
# Configure the compiler using the $CC set by Nix at build time
import strutils
let cc = getEnv"CC"
if cc.contains("gcc"):
switch("cc", "gcc")
elif cc.contains("clang"):
switch("cc", "clang")
WTF
mv config/nim.cfg config/nim.cfg.old
cat > config/nim.cfg << WTF
os = "${nimTarget.os}"
cpu = "${nimTarget.cpu}"
define:"nixbuild"
WTF
cat >> config/nim.cfg < config/nim.cfg.old
rm config/nim.cfg.old
cat >> config/nim.cfg << WTF
clang.cpp.exe %= "\$CXX"
clang.cpp.linkerexe %= "\$CXX"
clang.exe %= "\$CC"
clang.linkerexe %= "\$CC"
gcc.cpp.exe %= "\$CXX"
gcc.cpp.linkerexe %= "\$CXX"
gcc.exe %= "\$CC"
gcc.linkerexe %= "\$CC"
WTF
runHook postBuild
'';
wrapperArgs = lib.optionals (!(stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64)) [
"--prefix PATH : ${lib.makeBinPath [ buildPackages.gdb ]}:${
placeholder "out"
}/bin"
# Used by nim-gdb
"--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ openssl pcre ]}"
# These libraries may be referred to by the standard library.
# This is broken for cross-compilation because the package
# set will be shifted back by nativeBuildInputs.
"--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim"
# Use the custom configuration
];
installPhase = ''
runHook preInstall
mkdir -p $out/bin $out/etc
cp -r config $out/etc/nim
for binpath in ${nim'}/bin/nim?*; do
local binname=`basename $binpath`
makeWrapper \
$binpath $out/bin/${targetPlatformConfig}-$binname \
$wrapperArgs
ln -s $out/bin/${targetPlatformConfig}-$binname $out/bin/$binname
done
makeWrapper \
${nim'}/nim/bin/nim $out/bin/${targetPlatformConfig}-nim \
--set-default CC $(command -v $CC) \
--set-default CXX $(command -v $CXX) \
$wrapperArgs
ln -s $out/bin/${targetPlatformConfig}-nim $out/bin/nim
makeWrapper \
${nim'}/bin/testament $out/bin/${targetPlatformConfig}-testament \
$wrapperArgs
ln -s $out/bin/${targetPlatformConfig}-testament $out/bin/testament
'' + ''
runHook postInstall
'';
passthru = { nim = nim'; };
meta = nim'.meta // {
description = nim'.meta.description
+ " (${targetPlatformConfig} wrapper)";
platforms = with lib.platforms; unix ++ genode ++ windows;
};
});
in {
nim1 = wrapNim {
nim' = buildPackages.nim-unwrapped-1;
patches = [ ./nim.cfg.patch ];
};
}

View File

@ -15323,11 +15323,8 @@ with pkgs;
muonlang = callPackage ../development/compilers/muonlang { };
inherit (callPackages ../development/compilers/nim
{ inherit (darwin) Security; }
) nim1;
nim = nim2;
nim1 = nim-1_0;
nim2 = nim-2_2;
nim-unwrapped = nim-unwrapped-2_2;
nim-unwrapped-1 = nim-unwrapped-1_0;