tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nim: wrap compiler for cross-compilation support
Emery Hemingway
5 years ago
dc09e3ed
06ac3c1d
+259
-51
4 changed files
expand all
collapse all
unified
split
pkgs
applications
science
biology
mosdepth
default.nix
development
compilers
nim
NIM_CONFIG_DIR.patch
default.nix
top-level
all-packages.nix
+2
-1
pkgs/applications/science/biology/mosdepth/default.nix
reviewed
···
26
26
sha256 = "01gm9gj2x2zs4yx6wk761fi1papi7qr3gp4ln1kkn8n2f9y9h849";
27
27
};
28
28
29
29
-
buildInputs = [ nim htslib pcre ];
29
29
+
nativeBuildInputs = [ nim ];
30
30
+
buildInputs = [ htslib pcre ];
30
31
31
32
buildPhase = ''
32
33
HOME=$TMPDIR
+23
pkgs/development/compilers/nim/NIM_CONFIG_DIR.patch
reviewed
···
1
1
+
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim
2
2
+
index a470179bd..73cfa1a23 100644
3
3
+
--- a/compiler/nimconf.nim
4
4
+
+++ b/compiler/nimconf.nim
5
5
+
@@ -225,10 +225,15 @@ proc getUserConfigPath*(filename: RelativeFile): AbsoluteFile =
6
6
+
proc getSystemConfigPath*(conf: ConfigRef; filename: RelativeFile): AbsoluteFile =
7
7
+
# try standard configuration file (installation did not distribute files
8
8
+
# the UNIX way)
9
9
+
- let p = getPrefixDir(conf)
10
10
+
- result = p / RelativeDir"config" / filename
11
11
+
+ let
12
12
+
+ prefix = getPrefixDir(conf)
13
13
+
+ env = getEnv("NIM_CONFIG_PATH")
14
14
+
+ if env != "":
15
15
+
+ result = env.toAbsoluteDir / filename
16
16
+
+ else:
17
17
+
+ result = prefix / RelativeDir"config" / filename
18
18
+
when defined(unix):
19
19
+
- if not fileExists(result): result = p / RelativeDir"etc/nim" / filename
20
20
+
+ if not fileExists(result): result = prefix / RelativeDir"etc/nim" / filename
21
21
+
if not fileExists(result): result = AbsoluteDir"/etc/nim" / filename
22
22
+
23
23
+
proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
+232
-50
pkgs/development/compilers/nim/default.nix
reviewed
···
1
1
-
# based on https://github.com/nim-lang/Nim/blob/v0.18.0/.travis.yml
1
1
+
# https://nim-lang.github.io/Nim/packaging.html
2
2
3
3
-
{ stdenv, lib, fetchurl, makeWrapper, openssl, pcre, readline,
4
4
-
boehmgc, sfml, sqlite }:
3
3
+
{ stdenv, lib, fetchgit, fetchurl, makeWrapper, gdb, openssl, pcre, readline
4
4
+
, boehmgc, sqlite, nim-unwrapped, nim-stdlib, nim }:
5
5
6
6
-
stdenv.mkDerivation rec {
7
7
-
pname = "nim";
6
6
+
let
8
7
version = "1.2.6";
9
9
-
10
8
src = fetchurl {
11
11
-
url = "https://nim-lang.org/download/${pname}-${version}.tar.xz";
9
9
+
url = "https://nim-lang.org/download/nim-${version}.tar.xz";
12
10
sha256 = "0zk5qzxayqjw7kq6p92j4008g9bbyilyymhdc5xq9sln5rqym26z";
13
11
};
14
12
15
15
-
enableParallelBuilding = true;
13
13
+
meta = with lib; {
14
14
+
description = "Statically typed, imperative programming language";
15
15
+
homepage = "https://nim-lang.org/";
16
16
+
license = licenses.mit;
17
17
+
maintainers = with maintainers; [ ehmry ];
18
18
+
};
19
19
+
20
20
+
parseCpu = platform:
21
21
+
with platform;
22
22
+
# Derive a Nim CPU identifier
23
23
+
if isAarch32 then
24
24
+
"arm"
25
25
+
else if isAarch64 then
26
26
+
"arm64"
27
27
+
else if isAlpha then
28
28
+
"alpha"
29
29
+
else if isAvr then
30
30
+
"avr"
31
31
+
else if isMips && is32bit then
32
32
+
"mips"
33
33
+
else if isMips && is64bit then
34
34
+
"mips64"
35
35
+
else if isMsp430 then
36
36
+
"msp430"
37
37
+
else if isPowerPC && is32bit then
38
38
+
"powerpc"
39
39
+
else if isPowerPC && is64bit then
40
40
+
"powerpc64"
41
41
+
else if isRiscV && is64bit then
42
42
+
"riscv64"
43
43
+
else if isSparc then
44
44
+
"sparc"
45
45
+
else if isx86_32 then
46
46
+
"i386"
47
47
+
else if isx86_64 then
48
48
+
"amd64"
49
49
+
else
50
50
+
abort "no Nim CPU support known for ${config}";
51
51
+
52
52
+
parseOs = platform:
53
53
+
with platform;
54
54
+
# Derive a Nim OS identifier
55
55
+
if isAndroid then
56
56
+
"Android"
57
57
+
else if isDarwin then
58
58
+
"MacOSX"
59
59
+
else if isFreeBSD then
60
60
+
"FreeBSD"
61
61
+
else if isGenode then
62
62
+
"Genode"
63
63
+
else if isLinux then
64
64
+
"Linux"
65
65
+
else if isNetBSD then
66
66
+
"NetBSD"
67
67
+
else if isNone then
68
68
+
"Standalone"
69
69
+
else if isOpenBSD then
70
70
+
"OpenBSD"
71
71
+
else if isWindows then
72
72
+
"Windows"
73
73
+
else if isiOS then
74
74
+
"iOS"
75
75
+
else
76
76
+
abort "no Nim OS support known for ${config}";
16
77
17
17
-
NIX_LDFLAGS = "-lcrypto -lpcre -lreadline -lgc -lsqlite3";
78
78
+
parsePlatform = p: {
79
79
+
cpu = parseCpu p;
80
80
+
os = parseOs p;
81
81
+
};
18
82
19
19
-
# we could create a separate derivation for the "written in c" version of nim
20
20
-
# used for bootstrapping, but koch insists on moving the nim compiler around
21
21
-
# as part of building it, so it cannot be read-only
83
83
+
nimHost = parsePlatform stdenv.hostPlatform;
84
84
+
nimTarget = parsePlatform stdenv.targetPlatform;
22
85
23
23
-
nativeBuildInputs = [
24
24
-
makeWrapper
25
25
-
];
86
86
+
wrapperInputs = rec {
26
87
27
27
-
buildInputs = [
28
28
-
openssl pcre readline boehmgc sfml sqlite
29
29
-
];
88
88
+
bootstrap = stdenv.mkDerivation rec {
89
89
+
pname = "nim-bootstrap";
90
90
+
version = "0.20.0";
30
91
31
31
-
patches = [ ./nixbuild.patch ];
92
92
+
src = fetchgit {
93
93
+
# A Git checkout is much smaller than a GitHub tarball.
94
94
+
url = "https://github.com/nim-lang/csources.git";
95
95
+
rev = "v" + version;
96
96
+
sha256 = "0i6vsfy1sgapx43n226q8m0pvn159sw2mhp50zm3hhb9zfijanis";
97
97
+
};
32
98
33
33
-
postPatch = "echo define:nixbuild >> config/nim.cfg";
99
99
+
enableParallelBuilding = true;
34
100
35
35
-
buildPhase = ''
36
36
-
runHook preBuild
101
101
+
installPhase = ''
102
102
+
runHook preInstall
103
103
+
install -Dt $out/bin bin/nim
104
104
+
runHook postInstall
105
105
+
'';
106
106
+
};
37
107
38
38
-
# build.sh wants to write to $HOME/.cache
39
39
-
HOME=$TMPDIR
40
40
-
sh build.sh
41
41
-
./bin/nim c koch
42
42
-
./koch boot -d:release \
43
43
-
-d:useGnuReadline \
44
44
-
${lib.optionals (stdenv.isDarwin || stdenv.isLinux) "-d:nativeStacktrace"}
45
45
-
./koch tools -d:release
108
108
+
unwrapped = stdenv.mkDerivation {
109
109
+
# https://nim-lang.github.io/Nim/packaging.html
110
110
+
pname = "nim-unwrapped";
111
111
+
inherit version src;
46
112
47
47
-
runHook postBuild
48
48
-
'';
113
113
+
buildInputs = [ boehmgc openssl pcre readline sqlite ];
49
114
50
50
-
installPhase = ''
51
51
-
runHook preInstall
115
115
+
patches = [
116
116
+
./NIM_CONFIG_DIR.patch
117
117
+
# Override compiler configuration via an environmental variable
52
118
53
53
-
install -Dt $out/bin bin/* koch
54
54
-
./koch install $out
55
55
-
mv $out/nim/bin/* $out/bin/ && rmdir $out/nim/bin
56
56
-
mv $out/nim/* $out/ && rmdir $out/nim
119
119
+
./nixbuild.patch
120
120
+
# Load libraries at runtime by absolute path
121
121
+
];
57
122
123
123
+
configurePhase = ''
124
124
+
runHook preConfigure
125
125
+
cp ${bootstrap}/bin/nim bin/
126
126
+
echo 'define:nixbuild' >> config/nim.cfg
127
127
+
runHook postConfigure
128
128
+
'';
129
129
+
130
130
+
kochArgs = [
131
131
+
"--cpu:${nimHost.cpu}"
132
132
+
"--os:${nimHost.os}"
133
133
+
"-d:release"
134
134
+
"-d:useGnuReadline"
135
135
+
] ++ lib.optional (stdenv.isDarwin || stdenv.isLinux)
136
136
+
"-d:nativeStacktrace";
137
137
+
138
138
+
buildPhase = ''
139
139
+
runHook preBuild
140
140
+
local HOME=$TMPDIR
141
141
+
./bin/nim c koch
142
142
+
./koch boot $kochArgs --parallelBuild:$NIX_BUILD_CORES
143
143
+
./koch tools $kochArgs --parallelBuild:$NIX_BUILD_CORES
144
144
+
runHook postBuild
145
145
+
'';
146
146
+
147
147
+
installPhase = ''
148
148
+
runHook preInstall
149
149
+
install -Dt $out/bin bin/*
150
150
+
runHook postInstall
151
151
+
'';
152
152
+
153
153
+
inherit meta;
154
154
+
};
155
155
+
156
156
+
stdlib = stdenv.mkDerivation {
157
157
+
pname = "nim-stdlib";
158
158
+
inherit (nim-unwrapped) version src patches;
159
159
+
160
160
+
dontConfigure = true;
161
161
+
dontBuild = true;
162
162
+
163
163
+
installPhase = ''
164
164
+
runHook preInstall
165
165
+
touch bin/nim
166
166
+
./install.sh $TMPDIR
167
167
+
cp -r $TMPDIR/nim/lib $out
168
168
+
runHook postInstall
169
169
+
'';
170
170
+
171
171
+
meta = meta // {
172
172
+
description = meta.description + " (standard library)";
173
173
+
};
174
174
+
};
175
175
+
};
176
176
+
177
177
+
wrapped = let
178
178
+
nim = nim-unwrapped;
179
179
+
inherit (stdenv) targetPlatform;
180
180
+
in stdenv.mkDerivation {
181
181
+
name = "${targetPlatform.config}-nim-wrapper-${nim.version}";
182
182
+
inherit (nim) version;
183
183
+
preferLocalBuild = true;
184
184
+
185
185
+
nativeBuildInputs = [ makeWrapper ];
186
186
+
187
187
+
unpackPhase = ''
188
188
+
runHook preUnpack
189
189
+
tar xf ${nim.src} nim-$version/config/nim.cfg
190
190
+
cd nim-$version
191
191
+
runHook postUnpack
192
192
+
'';
193
193
+
194
194
+
dontConfigure = true;
195
195
+
196
196
+
wrapperArgs = [
197
197
+
"--prefix PATH : ${lib.makeBinPath [ stdenv.cc gdb ]}:${
198
198
+
placeholder "out"
199
199
+
}/bin"
200
200
+
"--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ stdenv.cc.libc openssl ]}"
201
201
+
"--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim"
202
202
+
];
203
203
+
204
204
+
buildPhase = with stdenv;
205
205
+
let
206
206
+
ccType = if cc.isGNU then
207
207
+
"gcc"
208
208
+
else if cc.isClang then
209
209
+
"clang"
210
210
+
else
211
211
+
abort "no Nim configuration available for ${cc.name}";
212
212
+
in ''
213
213
+
runHook preBuild
214
214
+
cat >> config/nim.cfg << EOF
215
215
+
216
216
+
define:nixbuild
217
217
+
os = ${nimTarget.os}
218
218
+
cpu = ${nimTarget.cpu}
219
219
+
cc = ${ccType}
220
220
+
EOF
221
221
+
222
222
+
mkdir -p $out/bin $out/etc/nim
223
223
+
export cc=$CC
224
224
+
export cxx=$CXX
225
225
+
substituteAll config/nim.cfg $out/etc/nim/nim.cfg \
226
226
+
--replace "cc = gcc" ""
227
227
+
228
228
+
for binpath in ${nim}/bin/nim?*; do
229
229
+
local binname=`basename $binpath`
230
230
+
makeWrapper $binpath $out/bin/${targetPlatform.config}-$binname \
231
231
+
$wrapperArgs
232
232
+
ln -s $out/bin/${targetPlatform.config}-$binname $out/bin/$binname
233
233
+
done
234
234
+
235
235
+
makeWrapper ${nim}/bin/nim $out/bin/${targetPlatform.config}-nim \
236
236
+
$wrapperArgs \
237
237
+
--set NIX_HARDENING_ENABLE "''${NIX_HARDENING_ENABLE/fortify}" \
238
238
+
--add-flags --lib:${nim-stdlib}
239
239
+
ln -s $out/bin/${targetPlatform.config}-nim $out/bin/nim
240
240
+
241
241
+
runHook postBuild
242
242
+
'';
58
243
# Fortify hardening appends -O2 to gcc flags which is unwanted for unoptimized nim builds.
59
59
-
wrapProgram $out/bin/nim \
60
60
-
--run 'NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}' \
61
61
-
--suffix PATH : ${lib.makeBinPath [ stdenv.cc ]}
244
244
+
245
245
+
dontInstall = true;
62
246
63
63
-
runHook postInstall
64
64
-
'';
247
247
+
meta = meta // {
248
248
+
description = nim.meta.description
249
249
+
+ " (${targetPlatform.config} wrapper)";
250
250
+
platforms = lib.platforms.unix;
251
251
+
};
65
252
66
66
-
meta = with stdenv.lib; {
67
67
-
description = "Statically typed, imperative programming language";
68
68
-
homepage = "https://nim-lang.org/";
69
69
-
license = licenses.mit;
70
70
-
maintainers = with maintainers; [ ehmry ];
71
71
-
platforms = with platforms; linux ++ darwin; # arbitrary
72
253
};
73
73
-
}
254
254
+
255
255
+
in wrapped // wrapperInputs
+2
pkgs/top-level/all-packages.nix
reviewed
···
9445
9445
mozart2-binary = callPackage ../development/compilers/mozart/binary.nix { };
9446
9446
9447
9447
nim = callPackage ../development/compilers/nim { };
9448
9448
+
nim-unwrapped = nim.unwrapped;
9449
9449
+
nim-stdlib = nim.stdlib;
9448
9450
nrpl = callPackage ../development/tools/nrpl { };
9449
9451
9450
9452
neko = callPackage ../development/compilers/neko { };