about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/nim/default.nix
blob: 53854d4fa35c354ccba03766b2bbe3b85bcb58ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# based on https://github.com/nim-lang/Nim/blob/v0.18.0/.travis.yml

{ stdenv, lib, fetchurl, makeWrapper, openssl, pcre, readline,
  boehmgc, sfml, sqlite }:

stdenv.mkDerivation rec {
  pname = "nim";
  version = "1.2.0";

  src = fetchurl {
    url = "https://nim-lang.org/download/${pname}-${version}.tar.xz";
    sha256 = "TpRYOjc5ZYIYBeZl4KBfUvthCRZnbtsJFIlBQVY3xXU=";
  };

  enableParallelBuilding = true;

  NIX_LDFLAGS = "-lcrypto -lpcre -lreadline -lgc -lsqlite3";

  # 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
  ];

  buildInputs = [
    openssl pcre readline boehmgc sfml sqlite
  ];

  buildPhase = ''
    runHook preBuild

    # 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

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    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

    # Fortify hardening appends -O2 to gcc flags which is unwanted for unoptimized nim builds.
    wrapProgram $out/bin/nim \
      --run 'NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}' \
      --suffix PATH : ${lib.makeBinPath [ stdenv.cc ]}

    runHook postInstall
  '';

  meta = with stdenv.lib; {
    description = "Statically typed, imperative programming language";
    homepage = "https://nim-lang.org/";
    license = licenses.mit;
    maintainers = with maintainers; [ ehmry ];
    platforms = with platforms; linux ++ darwin; # arbitrary
  };
}