From 3cfbadec99c6da8c64767a31055361f95ac3ebe5 Mon Sep 17 00:00:00 2001
From: Emery Hemingway <ehmry@posteo.net>
Date: Thu, 30 Sep 2021 11:27:38 +0200
Subject: [PATCH 1/2] nim: patch compiler to emit native file/line info format

---
 pkgs/development/compilers/nim/default.nix    |  2 +-
 .../compilers/nim/toLocation.patch            | 20 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 pkgs/development/compilers/nim/toLocation.patch

diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix
index 16896c8b6c05..2fe6f6edbfdc 100644
--- a/pkgs/development/compilers/nim/default.nix
+++ b/pkgs/development/compilers/nim/default.nix
@@ -114,7 +114,7 @@ in {
 
       ./nixbuild.patch
       # Load libraries at runtime by absolute path
-    ];
+    ] ++ lib.optional (!stdenv.hostPlatform.isWindows) ./toLocation.patch;
 
     configurePhase = ''
       runHook preConfigure
diff --git a/pkgs/development/compilers/nim/toLocation.patch b/pkgs/development/compilers/nim/toLocation.patch
new file mode 100644
index 000000000000..1cfa15fad6e5
--- /dev/null
+++ b/pkgs/development/compilers/nim/toLocation.patch
@@ -0,0 +1,20 @@
+diff --git a/lib/std/private/miscdollars.nim b/lib/std/private/miscdollars.nim
+index a41cf1bc1..5b92c696a 100644
+--- a/lib/std/private/miscdollars.nim
++++ b/lib/std/private/miscdollars.nim
+@@ -4,12 +4,12 @@ template toLocation*(result: var string, file: string | cstring, line: int, col:
+   # it can be done in a single place.
+   result.add file
+   if line > 0:
+-    result.add "("
++    result.add ':'
+     # simplify this after moving moving `include strmantle` above import assertions`
+     when declared(addInt): result.addInt line
+     else: result.add $line
+     if col > 0:
+-      result.add ", "
++      result.add ':'
+       when declared(addInt): result.addInt col
+       else: result.add $col
+-    result.add ")"
++    result.add ':'

From 30be6c22c53ef68c72ed745ba68dc6f87bfcd589 Mon Sep 17 00:00:00 2001
From: Emery Hemingway <ehmry@posteo.net>
Date: Tue, 19 Oct 2021 13:07:57 +0200
Subject: [PATCH 2/2] nim: 1.4.8 -> 1.6.0

---
 pkgs/development/compilers/nim/default.nix    |  4 +-
 pkgs/development/compilers/nim/nim.cfg.patch  | 41 +------------------
 .../compilers/nim/toLocation.patch            | 16 +++-----
 3 files changed, 9 insertions(+), 52 deletions(-)

diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix
index 2fe6f6edbfdc..c4be7c27d85c 100644
--- a/pkgs/development/compilers/nim/default.nix
+++ b/pkgs/development/compilers/nim/default.nix
@@ -98,12 +98,12 @@ in {
 
   nim-unwrapped = stdenv.mkDerivation rec {
     pname = "nim-unwrapped";
-    version = "1.4.8";
+    version = "1.6.0";
     strictDeps = true;
 
     src = fetchurl {
       url = "https://nim-lang.org/download/nim-${version}.tar.xz";
-      hash = "sha256-t5jFd0EdfZW4YxJh27Nnbp0a/Z42dA0ESWagVVtBRBo=";
+      hash = "sha256-UgZdSNcqcnAuwa/l96mDHhFnNTHiec3/nK7AGgfuxj0=";
     };
 
     buildInputs = [ boehmgc openssl pcre readline sqlite ];
diff --git a/pkgs/development/compilers/nim/nim.cfg.patch b/pkgs/development/compilers/nim/nim.cfg.patch
index a95b672d1c1d..7195132e52f6 100644
--- a/pkgs/development/compilers/nim/nim.cfg.patch
+++ b/pkgs/development/compilers/nim/nim.cfg.patch
@@ -1,5 +1,5 @@
 diff --git a/config/nim.cfg b/config/nim.cfg
-index a33a2f0a9..e069193ff 100644
+index 3b964d124..850ed0ed9 100644
 --- a/config/nim.cfg
 +++ b/config/nim.cfg
 @@ -8,26 +8,12 @@
@@ -29,42 +29,3 @@ index a33a2f0a9..e069193ff 100644
  path="$lib/deprecated/core"
  path="$lib/deprecated/pure"
  path="$lib/pure/collections"
-@@ -111,7 +97,7 @@ path="$lib/pure"
- @end
- 
- @if unix:
--  @if not bsd or haiku:
-+  @if not bsd or genode or haiku:
-     # -fopenmp
-     gcc.options.linker = "-ldl"
-     gcc.cpp.options.linker = "-ldl"
-@@ -295,29 +281,6 @@ vcc.cpp.options.size = "/O1"
- # Configuration for the Tiny C Compiler:
- tcc.options.always = "-w"
- 
--# Configuration for the Genode toolchain
--@if genode:
--  noCppExceptions # avoid std C++
--  tlsEmulation:on # no TLS segment register magic
--  @if i386 or amd64:
--    gcc.exe = "genode-x86-gcc"
--    gcc.cpp.exe = "genode-x86-g++"
--    gcc.cpp.linkerexe = "genode-x86-ld"
--  @elif arm:
--    gcc.exe = "genode-arm-gcc"
--    gcc.cpp.exe = "genode-arm-g++"
--    gcc.cpp.linkerexe = "genode-arm-ld"
--  @elif arm64:
--    gcc.exe = "genode-aarch64-gcc"
--    gcc.cpp.exe = "genode-aarch64-g++"
--    gcc.cpp.linkerexe = "genode-aarch64-ld"
--  @elif riscv64:
--    gcc.exe = "genode-riscv-gcc"
--    gcc.cpp.exe = "genode-riscv-g++"
--    gcc.cpp.linkerexe = "genode-riscv-ld"
--  @end
--@end
--
- @if arm or arm64:
-   --define:nimEmulateOverflowChecks
- @end
diff --git a/pkgs/development/compilers/nim/toLocation.patch b/pkgs/development/compilers/nim/toLocation.patch
index 1cfa15fad6e5..a3db46044049 100644
--- a/pkgs/development/compilers/nim/toLocation.patch
+++ b/pkgs/development/compilers/nim/toLocation.patch
@@ -1,20 +1,16 @@
 diff --git a/lib/std/private/miscdollars.nim b/lib/std/private/miscdollars.nim
-index a41cf1bc1..5b92c696a 100644
+index 840fedf54..6c3436308 100644
 --- a/lib/std/private/miscdollars.nim
 +++ b/lib/std/private/miscdollars.nim
-@@ -4,12 +4,12 @@ template toLocation*(result: var string, file: string | cstring, line: int, col:
+@@ -6,9 +6,8 @@ template toLocation*(result: var string, file: string | cstring, line: int, col:
    # it can be done in a single place.
    result.add file
    if line > 0:
 -    result.add "("
-+    result.add ':'
-     # simplify this after moving moving `include strmantle` above import assertions`
-     when declared(addInt): result.addInt line
-     else: result.add $line
++    result.add ":"
+     addInt(result, line)
      if col > 0:
 -      result.add ", "
-+      result.add ':'
-       when declared(addInt): result.addInt col
-       else: result.add $col
++      result.add ":"
+       addInt(result, col)
 -    result.add ")"
-+    result.add ':'