From 90f24ad0237af5cc625a3fec0d0d4843a44f3de2 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sun, 27 Oct 2024 18:29:54 +0000 Subject: [PATCH] nim-unwrapped-2_2: move to pkgs/by-name from nim-unwrapped-2 --- .../ni/nim-unwrapped-2_2/NIM_CONFIG_DIR.patch | 23 +++ .../nim-unwrapped-2_2/extra-mangling-2.patch | 48 +++++ .../ni/nim-unwrapped-2_2/nixbuild.patch | 40 ++++ .../ni/nim-unwrapped-2_2}/openssl.patch | 0 pkgs/by-name/ni/nim-unwrapped-2_2/package.nix | 187 ++++++++++++++++++ pkgs/development/compilers/nim/default.nix | 159 +-------------- pkgs/top-level/all-packages.nix | 4 +- 7 files changed, 303 insertions(+), 158 deletions(-) create mode 100644 pkgs/by-name/ni/nim-unwrapped-2_2/NIM_CONFIG_DIR.patch create mode 100644 pkgs/by-name/ni/nim-unwrapped-2_2/extra-mangling-2.patch create mode 100644 pkgs/by-name/ni/nim-unwrapped-2_2/nixbuild.patch rename pkgs/{development/compilers/nim => by-name/ni/nim-unwrapped-2_2}/openssl.patch (100%) create mode 100644 pkgs/by-name/ni/nim-unwrapped-2_2/package.nix diff --git a/pkgs/by-name/ni/nim-unwrapped-2_2/NIM_CONFIG_DIR.patch b/pkgs/by-name/ni/nim-unwrapped-2_2/NIM_CONFIG_DIR.patch new file mode 100644 index 000000000000..61e05b791cf8 --- /dev/null +++ b/pkgs/by-name/ni/nim-unwrapped-2_2/NIM_CONFIG_DIR.patch @@ -0,0 +1,23 @@ +diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim +index a470179bd..73cfa1a23 100644 +--- a/compiler/nimconf.nim ++++ b/compiler/nimconf.nim +@@ -225,10 +225,15 @@ proc getUserConfigPath*(filename: RelativeFile): AbsoluteFile = + proc getSystemConfigPath*(conf: ConfigRef; filename: RelativeFile): AbsoluteFile = + # try standard configuration file (installation did not distribute files + # the UNIX way) +- let p = getPrefixDir(conf) +- result = p / RelativeDir"config" / filename ++ let ++ prefix = getPrefixDir(conf) ++ env = getEnv("NIM_CONFIG_PATH") ++ if env != "": ++ result = env.toAbsoluteDir / filename ++ else: ++ result = prefix / RelativeDir"config" / filename + when defined(unix): +- if not fileExists(result): result = p / RelativeDir"etc/nim" / filename ++ if not fileExists(result): result = prefix / RelativeDir"etc/nim" / filename + if not fileExists(result): result = AbsoluteDir"/etc/nim" / filename + + proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) = diff --git a/pkgs/by-name/ni/nim-unwrapped-2_2/extra-mangling-2.patch b/pkgs/by-name/ni/nim-unwrapped-2_2/extra-mangling-2.patch new file mode 100644 index 000000000000..dfee7d8675ce --- /dev/null +++ b/pkgs/by-name/ni/nim-unwrapped-2_2/extra-mangling-2.patch @@ -0,0 +1,48 @@ +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..> config/nim.cfg + runHook postConfigure + ''; + + kochArgs = + [ + "--cpu:${nimHost.cpu}" + "--os:${nimHost.os}" + "-d:release" + "-d:useGnuReadline" + ] + ++ lib.optional (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isLinux) "-d:nativeStacktrace"; + + preBuild = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) '' + substituteInPlace makefile \ + --replace "aarch64" "arm64" + ''; + + buildPhase = '' + runHook preBuild + local HOME=$TMPDIR + ./bin/nim c --parallelBuild:$NIX_BUILD_CORES koch + ./koch boot $kochArgs --parallelBuild:$NIX_BUILD_CORES + ./koch toolsNoExternal $kochArgs --parallelBuild:$NIX_BUILD_CORES + ./bin/nim js -d:release tools/dochack/dochack.nim + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + install -Dt $out/bin bin/* + ln -sf $out/nim/bin/nim $out/bin/nim + ln -sf $out/nim/lib $out/lib + ./install.sh $out + cp -a tools dist $out/nim/ + runHook postInstall + ''; + + passthru = { + inherit nimHost nimTarget; + }; + + meta = with lib; { + description = "Statically typed, imperative programming language"; + homepage = "https://nim-lang.org/"; + license = licenses.mit; + mainProgram = "nim"; + maintainers = with maintainers; [ + ehmry + eveeifyeve + ]; + }; + +}) diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix index 88d21c75a981..9a4155f6974a 100644 --- a/pkgs/development/compilers/nim/default.nix +++ b/pkgs/development/compilers/nim/default.nix @@ -6,164 +6,9 @@ , nim-unwrapped-2, nim-unwrapped-1, nim }: let - parseCpu = platform: - with platform; - # Derive a Nim CPU identifier - if isAarch32 then - "arm" - else if isAarch64 then - "arm64" - else if isAlpha then - "alpha" - else if isAvr then - "avr" - else if isMips && is32bit then - "mips" - else if isMips && is64bit then - "mips64" - else if isMsp430 then - "msp430" - else if isPower && is32bit then - "powerpc" - else if isPower && is64bit then - "powerpc64" - else if isRiscV && is64bit then - "riscv64" - else if isSparc then - "sparc" - else if isx86_32 then - "i386" - else if isx86_64 then - "amd64" - else - abort "no Nim CPU support known for ${config}"; - - parseOs = platform: - with platform; - # Derive a Nim OS identifier - if isAndroid then - "Android" - else if isDarwin then - "MacOSX" - else if isFreeBSD then - "FreeBSD" - else if isGenode then - "Genode" - else if isLinux then - "Linux" - else if isNetBSD then - "NetBSD" - else if isNone then - "Standalone" - else if isOpenBSD then - "OpenBSD" - else if isWindows then - "Windows" - else if isiOS then - "iOS" - else - abort "no Nim OS support known for ${config}"; - - parsePlatform = p: { - cpu = parseCpu p; - os = parseOs p; - }; - - nimHost = parsePlatform stdenv.hostPlatform; - nimTarget = parsePlatform stdenv.targetPlatform; - + inherit (nim-unwrapped-2.passthru) nimHost nimTarget; in { - nim-unwrapped-2 = stdenv.mkDerivation (finalAttrs: { - pname = "nim-unwrapped"; - version = "2.2.0"; - strictDeps = true; - - src = fetchurl { - url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz"; - hash = "sha256-zphChJyXYOSH7N0c2t98DyhEyvrmBUAcfHKuJXZEiTw="; - }; - - buildInputs = [ boehmgc openssl pcre readline sqlite ] - ++ lib.optional stdenv.hostPlatform.isDarwin Security; - - patches = [ - ./NIM_CONFIG_DIR.patch - # Override compiler configuration via an environmental variable - - ./nixbuild.patch - # Load libraries at runtime by absolute path - - ./extra-mangling-2.patch - # Mangle store paths of modules to prevent runtime dependence. - - ./openssl.patch - # dlopen is widely used by Python, Ruby, Perl, ... what you're really telling me here is that your OS is fundamentally broken. That might be news for you, but it isn't for me. - ]; - - configurePhase = let - bootstrapCompiler = stdenv.mkDerivation { - pname = "nim-bootstrap"; - inherit (finalAttrs) version src preBuild; - enableParallelBuilding = true; - installPhase = '' - runHook preInstall - install -Dt $out/bin bin/nim - runHook postInstall - ''; - }; - in '' - runHook preConfigure - cp ${bootstrapCompiler}/bin/nim bin/ - echo 'define:nixbuild' >> config/nim.cfg - runHook postConfigure - ''; - - kochArgs = [ - "--cpu:${nimHost.cpu}" - "--os:${nimHost.os}" - "-d:release" - "-d:useGnuReadline" - ] ++ lib.optional (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isLinux) "-d:nativeStacktrace"; - - preBuild = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) '' - substituteInPlace makefile \ - --replace "aarch64" "arm64" - ''; - - buildPhase = '' - runHook preBuild - local HOME=$TMPDIR - ./bin/nim c --parallelBuild:$NIX_BUILD_CORES koch - ./koch boot $kochArgs --parallelBuild:$NIX_BUILD_CORES - ./koch toolsNoExternal $kochArgs --parallelBuild:$NIX_BUILD_CORES - ./bin/nim js -d:release tools/dochack/dochack.nim - runHook postBuild - ''; - - installPhase = '' - runHook preInstall - install -Dt $out/bin bin/* - ln -sf $out/nim/bin/nim $out/bin/nim - ln -sf $out/nim/lib $out/lib - ./install.sh $out - cp -a tools dist $out/nim/ - runHook postInstall - ''; - - passthru = { - updateScript.command = [ ./update.sh ]; - }; - - meta = with lib; { - description = "Statically typed, imperative programming language"; - homepage = "https://nim-lang.org/"; - license = licenses.mit; - mainProgram = "nim"; - maintainers = with maintainers; [ ehmry eveeifyeve ]; - }; - }); - nim-unwrapped-1 = nim-unwrapped-2.overrideAttrs (finalAttrs: prevAttrs: { version = "1.6.20"; src = fetchurl { @@ -313,7 +158,7 @@ in { in { nim2 = wrapNim { - nim' = buildPackages.nim-unwrapped-2; + nim' = buildPackages.nim-unwrapped-2_2; patches = [ ./nim2.cfg.patch ]; }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d8c91ae92e68..20b9edb0e07a 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15325,8 +15325,10 @@ with pkgs; inherit (callPackages ../development/compilers/nim { inherit (darwin) Security; } - ) nim-unwrapped-1 nim-unwrapped-2 nim1 nim2; + ) nim-unwrapped-1 nim1 nim2; nim = nim2; + 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 { };