diff --git a/pkgs/development/compilers/nim/nim2.cfg.patch b/pkgs/by-name/ni/nim-2_2/nim2.cfg.patch similarity index 100% rename from pkgs/development/compilers/nim/nim2.cfg.patch rename to pkgs/by-name/ni/nim-2_2/nim2.cfg.patch diff --git a/pkgs/by-name/ni/nim-2_2/package.nix b/pkgs/by-name/ni/nim-2_2/package.nix new file mode 100644 index 000000000000..f97506eb624a --- /dev/null +++ b/pkgs/by-name/ni/nim-2_2/package.nix @@ -0,0 +1,156 @@ +# When updating this package please check that all other versions of Nim +# evaluate because they reuse definitions from the latest compiler. +{ + lib, + stdenv, + buildPackages, + darwin, + makeWrapper, + openssl, + pcre, + nim-unwrapped-2_2 ? buildPackages.nim-unwrapped-2_2, + Security ? darwin.Security, +}: + +let + wrapNim = + { nimUnwrapped, patches }: + let + targetPlatformConfig = stdenv.targetPlatform.config; + in + stdenv.mkDerivation (finalAttrs: { + name = "${targetPlatformConfig}-nim-wrapper-${nimUnwrapped.version}"; + inherit (nimUnwrapped) 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 ${nimUnwrapped.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", "${nimUnwrapped.passthru.nimTarget.os}") + switch("cpu", "${nimUnwrapped.passthru.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 = "${nimUnwrapped.passthru.nimTarget.os}" + cpu = "${nimUnwrapped.passthru.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 ${nimUnwrapped}/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 \ + ${nimUnwrapped}/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 \ + ${nimUnwrapped}/bin/testament $out/bin/${targetPlatformConfig}-testament \ + $wrapperArgs + ln -s $out/bin/${targetPlatformConfig}-testament $out/bin/testament + + '' + + '' + runHook postInstall + ''; + + passthru = nimUnwrapped.passthru // { + inherit wrapNim; + nim = nimUnwrapped; + }; + + meta = nimUnwrapped.meta // { + description = nimUnwrapped.meta.description + " (${targetPlatformConfig} wrapper)"; + platforms = with lib.platforms; unix ++ genode ++ windows; + }; + }); +in +wrapNim { + nimUnwrapped = nim-unwrapped-2_2; + patches = [ ./nim2.cfg.patch ]; +} diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix index 9a4155f6974a..cbef7efb1d19 100644 --- a/pkgs/development/compilers/nim/default.nix +++ b/pkgs/development/compilers/nim/default.nix @@ -3,7 +3,7 @@ { lib, callPackage, buildPackages, stdenv, fetchurl, fetchgit , makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security -, nim-unwrapped-2, nim-unwrapped-1, nim }: +, nim-unwrapped-2, nim-unwrapped-1 }: let inherit (nim-unwrapped-2.passthru) nimHost nimTarget; @@ -157,11 +157,6 @@ in { }); in { - nim2 = wrapNim { - nim' = buildPackages.nim-unwrapped-2_2; - patches = [ ./nim2.cfg.patch ]; - }; - nim1 = wrapNim { nim' = buildPackages.nim-unwrapped-1; patches = [ ./nim.cfg.patch ]; diff --git a/pkgs/development/compilers/nim/extra-mangling-2.patch b/pkgs/development/compilers/nim/extra-mangling-2.patch deleted file mode 100644 index dfee7d8675ce..000000000000 --- a/pkgs/development/compilers/nim/extra-mangling-2.patch +++ /dev/null @@ -1,48 +0,0 @@ -diff --git a/compiler/modulepaths.nim b/compiler/modulepaths.nim -index c9e6060e5..acb289498 100644 ---- a/compiler/modulepaths.nim -+++ b/compiler/modulepaths.nim -@@ -79,6 +79,13 @@ proc checkModuleName*(conf: ConfigRef; n: PNode; doLocalError=true): FileIndex = - else: - result = fileInfoIdx(conf, fullPath) - -+proc rot13(result: var string) = -+ for i, c in result: -+ case c -+ of 'a'..'m', 'A'..'M': result[i] = char(c.uint8 + 13) -+ of 'n'..'z', 'N'..'Z': result[i] = char(c.uint8 - 13) -+ else: discard -+ - proc mangleModuleName*(conf: ConfigRef; path: AbsoluteFile): string = - ## Mangle a relative module path to avoid path and symbol collisions. - ## -@@ -87,9 +94,11 @@ proc mangleModuleName*(conf: ConfigRef; path: AbsoluteFile): string = - ## - ## Example: - ## `foo-#head/../bar` becomes `@foo-@hhead@s..@sbar` -- "@m" & relativeTo(path, conf.projectPath).string.multiReplace( -+ result = "@m" & relativeTo(path, conf.projectPath).string.multiReplace( - {$os.DirSep: "@s", $os.AltSep: "@s", "#": "@h", "@": "@@", ":": "@c"}) -+ rot13(result) - - proc demangleModuleName*(path: string): string = - ## Demangle a relative module path. - result = path.multiReplace({"@@": "@", "@h": "#", "@s": "/", "@m": "", "@c": ":"}) -+ rot13(result) -diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim -index 77762d23a..59dd8903a 100644 ---- a/compiler/modulegraphs.nim -+++ b/compiler/modulegraphs.nim -@@ -503,7 +503,11 @@ proc uniqueModuleName*(conf: ConfigRef; m: PSym): string = - for i in 0../dev/null && pwd)" - -curl_github() { - curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} "$@" -} - - -case "$UPDATE_NIX_ATTR_PATH" in -nim) - latestTag=$(curl_github https://api.github.com/repos/nim-lang/Nim/releases/latest | jq -r ".tag_name") - latestVersion="$(expr "$latestTag" : 'v\(.*\)')" - - echo "Updating Nim" - nix-update --version "$latestVersion" \ - --override-filename "$SCRIPT_DIR/default.nix" \ - nim -*) - echo "Unknown attr path $UPDATE_NIX_ATTR_PATH" - ;; -esac diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 20b9edb0e07a..e7fa059de8ab 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15325,10 +15325,13 @@ with pkgs; inherit (callPackages ../development/compilers/nim { inherit (darwin) Security; } - ) nim-unwrapped-1 nim1 nim2; + ) nim1; + nim = nim2; + nim2 = nim-2_2; nim-unwrapped = nim-unwrapped-2_2; nim-unwrapped-2 = nim-unwrapped-2_2; + buildNimPackage = callPackage ../development/compilers/nim/build-nim-package.nix { }; nimOverrides = callPackage ./nim-overrides.nix { };