audiobookshelf: 2.18.1 -> 2.19.0 (#378967)
[NixPkgs.git] / pkgs / by-name / ni / nim-unwrapped-2_2 / package.nix
blob41307f320271556441b4a7fc4e0a092b26e86106
1 # When updating this package please check that all other versions of Nim
2 # evaluate because they reuse definitions from the latest compiler.
4   lib,
5   stdenv,
6   fetchurl,
7   boehmgc,
8   openssl,
9   pcre,
10   readline,
11   sqlite,
12   darwin,
13   Security ? darwin.Security,
16 let
17   parseCpu =
18     platform:
19     with platform;
20     # Derive a Nim CPU identifier
21     if isAarch32 then
22       "arm"
23     else if isAarch64 then
24       "arm64"
25     else if isAlpha then
26       "alpha"
27     else if isAvr then
28       "avr"
29     else if isMips && is32bit then
30       "mips"
31     else if isMips && is64bit then
32       "mips64"
33     else if isMsp430 then
34       "msp430"
35     else if isPower && is32bit then
36       "powerpc"
37     else if isPower && is64bit then
38       "powerpc64"
39     else if isRiscV && is64bit then
40       "riscv64"
41     else if isSparc then
42       "sparc"
43     else if isx86_32 then
44       "i386"
45     else if isx86_64 then
46       "amd64"
47     else
48       throw "no Nim CPU support known for ${config}";
50   parseOs =
51     platform:
52     with platform;
53     # Derive a Nim OS identifier
54     if isAndroid then
55       "Android"
56     else if isDarwin then
57       "MacOSX"
58     else if isFreeBSD then
59       "FreeBSD"
60     else if isGenode then
61       "Genode"
62     else if isLinux then
63       "Linux"
64     else if isNetBSD then
65       "NetBSD"
66     else if isNone then
67       "Standalone"
68     else if isOpenBSD then
69       "OpenBSD"
70     else if isWindows then
71       "Windows"
72     else if isiOS then
73       "iOS"
74     else
75       throw "no Nim OS support known for ${config}";
77   parsePlatform = p: {
78     cpu = parseCpu p;
79     os = parseOs p;
80   };
82   nimHost = parsePlatform stdenv.hostPlatform;
83   nimTarget = parsePlatform stdenv.targetPlatform;
86 stdenv.mkDerivation (finalAttrs: {
87   pname = "nim-unwrapped";
88   version = "2.2.0";
89   strictDeps = true;
91   src = fetchurl {
92     url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz";
93     hash = "sha256-zphChJyXYOSH7N0c2t98DyhEyvrmBUAcfHKuJXZEiTw=";
94   };
96   buildInputs = [
97     boehmgc
98     openssl
99     pcre
100     readline
101     sqlite
102   ] ++ lib.optional stdenv.hostPlatform.isDarwin Security;
104   patches = [
105     ./NIM_CONFIG_DIR.patch
106     # Override compiler configuration via an environmental variable
108     ./nixbuild.patch
109     # Load libraries at runtime by absolute path
111     ./extra-mangling-2.patch
112     # Mangle store paths of modules to prevent runtime dependence.
114     ./openssl.patch
115     # 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.
116   ];
118   configurePhase =
119     let
120       bootstrapCompiler = stdenv.mkDerivation {
121         pname = "nim-bootstrap";
122         inherit (finalAttrs) version src preBuild;
123         enableParallelBuilding = true;
124         installPhase = ''
125           runHook preInstall
126           install -Dt $out/bin bin/nim
127           runHook postInstall
128         '';
129       };
130     in
131     ''
132       runHook preConfigure
133       cp ${bootstrapCompiler}/bin/nim bin/
134       echo 'define:nixbuild' >> config/nim.cfg
135       runHook postConfigure
136     '';
138   kochArgs =
139     [
140       "--cpu:${nimHost.cpu}"
141       "--os:${nimHost.os}"
142       "-d:release"
143       "-d:useGnuReadline"
144     ]
145     ++ lib.optional (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isLinux) "-d:nativeStacktrace";
147   preBuild = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
148     substituteInPlace makefile \
149       --replace "aarch64" "arm64"
150   '';
152   buildPhase = ''
153     runHook preBuild
154     local HOME=$TMPDIR
155     ./bin/nim c --parallelBuild:$NIX_BUILD_CORES koch
156     ./koch boot $kochArgs --parallelBuild:$NIX_BUILD_CORES
157     ./koch toolsNoExternal $kochArgs --parallelBuild:$NIX_BUILD_CORES
158     ./bin/nim js -d:release tools/dochack/dochack.nim
159     runHook postBuild
160   '';
162   installPhase = ''
163     runHook preInstall
164     install -Dt $out/bin bin/*
165     ln -sf $out/nim/bin/nim $out/bin/nim
166     ln -sf $out/nim/lib $out/lib
167     ./install.sh $out
168     cp -a tools dist $out/nim/
169     runHook postInstall
170   '';
172   passthru = {
173     inherit nimHost nimTarget;
174   };
176   meta = with lib; {
177     description = "Statically typed, imperative programming language";
178     homepage = "https://nim-lang.org/";
179     license = licenses.mit;
180     mainProgram = "nim";
181     maintainers = with maintainers; [
182       ehmry
183       eveeifyeve
184     ];
185   };