about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/nim/default.nix
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:36 +0000
committerAlyssa Ross <hi@alyssa.is>2019-01-07 02:18:47 +0000
commit36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2 (patch)
treeb3faaf573407b32aa645237a4d16b82778a39a92 /nixpkgs/pkgs/development/compilers/nim/default.nix
parent4e31070265257dc67d120c27e0f75c2344fdfa9a (diff)
parentabf060725d7614bd3b9f96764262dfbc2f9c2199 (diff)
downloadnixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.gz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.bz2
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.lz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.xz
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.tar.zst
nixlib-36f56d99fa0a0765c9f1de4a5f17a9b05830c3f2.zip
Add 'nixpkgs/' from commit 'abf060725d7614bd3b9f96764262dfbc2f9c2199'
git-subtree-dir: nixpkgs
git-subtree-mainline: 4e31070265257dc67d120c27e0f75c2344fdfa9a
git-subtree-split: abf060725d7614bd3b9f96764262dfbc2f9c2199
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/nim/default.nix')
-rw-r--r--nixpkgs/pkgs/development/compilers/nim/default.nix90
1 files changed, 90 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/compilers/nim/default.nix b/nixpkgs/pkgs/development/compilers/nim/default.nix
new file mode 100644
index 000000000000..ae36041b33eb
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/nim/default.nix
@@ -0,0 +1,90 @@
+# based on https://github.com/nim-lang/Nim/blob/v0.18.0/.travis.yml
+
+{ stdenv, lib, fetchurl, makeWrapper, nodejs-slim-10_x, openssl, pcre, readline, boehmgc, sfml, tzdata, coreutils }:
+
+stdenv.mkDerivation rec {
+  name = "nim-${version}";
+  version = "0.19.0";
+
+  src = fetchurl {
+    url = "https://nim-lang.org/download/${name}.tar.xz";
+    sha256 = "0biwvw1gividp5lkf0daq1wp9v6ms4xy6dkf5zj0sn9w4m3n76d1";
+  };
+
+  doCheck = !stdenv.isDarwin;
+
+  enableParallelBuilding = true;
+
+  NIX_LDFLAGS = [
+    "-lcrypto"
+    "-lpcre"
+    "-lreadline"
+    "-lgc"
+  ];
+
+  # 1. nodejs is only needed for tests
+  # 2. we could create a separate derivation for the "written in c" version of nim
+  #    used for bootstrapping, but koch insists on moving the nim compiler around
+  #    as part of building it, so it cannot be read-only
+
+  nativeBuildInputs = [
+    makeWrapper nodejs-slim-10_x tzdata coreutils
+  ];
+
+  buildInputs = [
+    openssl pcre readline boehmgc sfml
+  ];
+
+  phases = [ "unpackPhase" "patchPhase" "buildPhase" "installPhase" "checkPhase" ];
+
+  buildPhase = ''
+    # use $CC to trigger the linker since calling ld in build.sh causes an error
+    LD=$CC
+    # build.sh wants to write to $HOME/.cache
+    HOME=$TMPDIR
+    sh build.sh
+    ./bin/nim c koch
+    ./koch boot  -d:release \
+                 -d:useGnuReadline \
+                 ${lib.optionals (stdenv.isDarwin || stdenv.isLinux) "-d:nativeStacktrace"}
+    ./koch tools -d:release
+  '';
+
+  installPhase = ''
+    install -Dt $out/bin bin/* koch
+    ./koch install $out
+    mv $out/nim/bin/* $out/bin/ && rmdir $out/nim/bin
+    mv $out/nim/*     $out/     && rmdir $out/nim
+    wrapProgram $out/bin/nim \
+      --suffix PATH : ${lib.makeBinPath [ stdenv.cc ]}
+  '';
+
+  patchPhase =
+    let disableTest = ''sed -i '1i discard \"\"\"\n  disabled: true\n\"\"\"\n\n' '';
+        disableStdLibTest = ''sed -i -e '/^when isMainModule/,/^END$/{s/^/#/}' '';
+        disableCompile = ''sed -i -e 's/^/#/' '';
+    in ''
+      substituteInPlace ./tests/async/tioselectors.nim --replace "/bin/sleep" "sleep"
+      substituteInPlace ./tests/osproc/tworkingdir.nim --replace "/usr/bin" "${coreutils}/bin"
+      substituteInPlace ./tests/stdlib/ttimes.nim --replace "/usr/share/zoneinfo" "${tzdata}/share/zoneinfo"
+
+      # disable tests requiring network access (not available in the build container)
+      ${disableTest} ./tests/stdlib/thttpclient.nim
+    '' + lib.optionalString stdenv.isAarch64 ''
+      # disable test supposedly broken on aarch64
+      ${disableStdLibTest} ./lib/pure/stats.nim
+    '';
+
+  checkPhase = ''
+    PATH=$PATH:$out/bin
+    ./koch tests
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Statically typed, imperative programming language";
+    homepage = https://nim-lang.org/;
+    license = licenses.mit;
+    maintainers = with maintainers; [ ehmry peterhoeg ];
+    platforms = with platforms; linux ++ darwin; # arbitrary
+  };
+}