fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{
2 stdenv,
3 callPackage,
4 fetchFromGitHub,
5 fetchurl,
6 lib,
7 replaceVars,
8 # Dependencies
9 boehmgc,
10 coreutils,
11 git,
12 gmp,
13 hostname,
14 libevent,
15 libiconv,
16 libxml2,
17 libyaml,
18 libffi,
19 llvmPackages_15,
20 llvmPackages_18,
21 makeWrapper,
22 openssl,
23 pcre2,
24 pkg-config,
25 installShellFiles,
26 readline,
27 tzdata,
28 which,
29 zlib,
30}:
31
32# We need to keep around at least the latest version released with a stable
33# NixOS
34let
35 archs = {
36 x86_64-linux = "linux-x86_64";
37 i686-linux = "linux-i686";
38 x86_64-darwin = "darwin-universal";
39 aarch64-darwin = "darwin-universal";
40 aarch64-linux = "linux-aarch64";
41 };
42
43 arch = archs.${stdenv.system} or (throw "system ${stdenv.system} not supported");
44
45 nativeCheckInputs = [
46 git
47 gmp
48 openssl
49 readline
50 libxml2
51 libyaml
52 libffi
53 ];
54
55 binaryUrl =
56 version: rel:
57 if arch == archs.aarch64-linux then
58 "https://dev.alpinelinux.org/archive/crystal/crystal-${version}-aarch64-alpine-linux-musl.tar.gz"
59 else
60 "https://github.com/crystal-lang/crystal/releases/download/${version}/crystal-${version}-${toString rel}-${arch}.tar.gz";
61
62 genericBinary =
63 {
64 version,
65 sha256s,
66 rel ? 1,
67 }:
68 stdenv.mkDerivation rec {
69 pname = "crystal-binary";
70 inherit version;
71
72 src = fetchurl {
73 url = binaryUrl version rel;
74 sha256 = sha256s.${stdenv.system};
75 };
76
77 buildCommand = ''
78 mkdir -p $out
79 tar --strip-components=1 -C $out -xf ${src}
80 patchShebangs $out/bin/crystal
81 '';
82
83 meta.platforms = lib.attrNames sha256s;
84 };
85
86 generic =
87 {
88 version,
89 sha256,
90 binary,
91 llvmPackages,
92 doCheck ? true,
93 extraBuildInputs ? [ ],
94 buildFlags ? [
95 "all"
96 "docs"
97 "release=1"
98 ],
99 }:
100 stdenv.mkDerivation (finalAttrs: {
101 pname = "crystal";
102 inherit buildFlags doCheck version;
103
104 src = fetchFromGitHub {
105 owner = "crystal-lang";
106 repo = "crystal";
107 rev = version;
108 inherit sha256;
109 };
110
111 patches = [
112 (replaceVars ./tzdata.patch {
113 inherit tzdata;
114 })
115 ];
116
117 outputs = [
118 "out"
119 "lib"
120 "bin"
121 ];
122
123 postPatch =
124 ''
125 export TMP=$(mktemp -d)
126 export HOME=$TMP
127 export TMPDIR=$TMP
128 mkdir -p $HOME/test
129
130 # Add dependency of crystal to docs to avoid issue on flag changes between releases
131 # https://github.com/crystal-lang/crystal/pull/8792#issuecomment-614004782
132 substituteInPlace Makefile \
133 --replace 'docs: ## Generate standard library documentation' 'docs: crystal ## Generate standard library documentation'
134
135 mkdir -p $TMP/crystal
136
137 substituteInPlace spec/std/file_spec.cr \
138 --replace '/bin/ls' '${coreutils}/bin/ls' \
139 --replace '/usr/share' "$TMP/crystal" \
140 --replace '/usr' "$TMP" \
141 --replace '/tmp' "$TMP"
142
143 substituteInPlace spec/std/process_spec.cr \
144 --replace '/bin/cat' '${coreutils}/bin/cat' \
145 --replace '/bin/ls' '${coreutils}/bin/ls' \
146 --replace '/usr/bin/env' '${coreutils}/bin/env' \
147 --replace '"env"' '"${coreutils}/bin/env"' \
148 --replace '/usr' "$TMP" \
149 --replace '/tmp' "$TMP"
150
151 substituteInPlace spec/std/system_spec.cr \
152 --replace '`hostname`' '`${hostname}/bin/hostname`'
153
154 # See https://github.com/crystal-lang/crystal/issues/8629
155 substituteInPlace spec/std/socket/udp_socket_spec.cr \
156 --replace 'it "joins and transmits to multicast groups"' 'pending "joins and transmits to multicast groups"'
157
158 ''
159 + lib.optionalString (stdenv.cc.isClang && (stdenv.cc.libcxx != null)) ''
160 # Darwin links against libc++ not libstdc++. Newer versions of clang (12+) require
161 # libc++abi to be linked explicitly (see https://github.com/NixOS/nixpkgs/issues/166205).
162 substituteInPlace src/llvm/lib_llvm.cr \
163 --replace '@[Link("stdc++")]' '@[Link("c++")]'
164 '';
165
166 # Defaults are 4
167 preBuild = ''
168 export CRYSTAL_WORKERS=$NIX_BUILD_CORES
169 export threads=$NIX_BUILD_CORES
170 export CRYSTAL_CACHE_DIR=$TMP
171 export MACOSX_DEPLOYMENT_TARGET=10.11
172 '';
173
174 strictDeps = true;
175 nativeBuildInputs = [
176 binary
177 makeWrapper
178 which
179 pkg-config
180 llvmPackages.llvm
181 installShellFiles
182 ];
183 buildInputs =
184 [
185 boehmgc
186 pcre2
187 libevent
188 libyaml
189 zlib
190 libxml2
191 openssl
192 ]
193 ++ extraBuildInputs
194 ++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
195
196 makeFlags = [
197 "CRYSTAL_CONFIG_VERSION=${version}"
198 "progress=1"
199 ];
200
201 LLVM_CONFIG = "${llvmPackages.llvm.dev}/bin/llvm-config";
202
203 FLAGS = [
204 "--single-module" # needed for deterministic builds
205 ];
206
207 # This makes sure we don't keep depending on the previous version of
208 # crystal used to build this one.
209 CRYSTAL_LIBRARY_PATH = "${placeholder "lib"}/crystal";
210
211 # We *have* to add `which` to the PATH or crystal is unable to build
212 # stuff later if which is not available.
213 installPhase = ''
214 runHook preInstall
215
216 install -Dm755 .build/crystal $bin/bin/crystal
217 wrapProgram $bin/bin/crystal \
218 --suffix PATH : ${
219 lib.makeBinPath [
220 pkg-config
221 llvmPackages.clang
222 which
223 ]
224 } \
225 --suffix CRYSTAL_PATH : lib:$lib/crystal \
226 --suffix PKG_CONFIG_PATH : ${
227 lib.makeSearchPathOutput "dev" "lib/pkgconfig" finalAttrs.buildInputs
228 } \
229 --suffix CRYSTAL_LIBRARY_PATH : ${lib.makeLibraryPath finalAttrs.buildInputs}
230 install -dm755 $lib/crystal
231 cp -r src/* $lib/crystal/
232
233 install -dm755 $out/share/doc/crystal/api
234 cp -r docs/* $out/share/doc/crystal/api/
235 cp -r samples $out/share/doc/crystal/
236
237 installShellCompletion --cmd ${finalAttrs.meta.mainProgram} etc/completion.*
238
239 installManPage man/crystal.1
240
241 install -Dm644 -t $out/share/licenses/crystal LICENSE README.md
242
243 mkdir -p $out
244 ln -s $bin/bin $out/bin
245 ln -s $bin/share/bash-completion $out/share/bash-completion
246 ln -s $bin/share/zsh $out/share/zsh
247 # fish completion was introduced in 1.6.0
248 test -f etc/completion.fish && ln -s $bin/share/fish $out/share/fish
249 ln -s $lib $out/lib
250
251 runHook postInstall
252 '';
253
254 enableParallelBuilding = true;
255
256 dontStrip = true;
257
258 checkTarget = "compiler_spec";
259
260 preCheck = ''
261 export LIBRARY_PATH=${lib.makeLibraryPath nativeCheckInputs}:$LIBRARY_PATH
262 export PATH=${lib.makeBinPath nativeCheckInputs}:$PATH
263 '';
264
265 passthru.buildBinary = binary;
266 passthru.buildCrystalPackage = callPackage ./build-package.nix {
267 crystal = finalAttrs.finalPackage;
268 };
269 passthru.llvmPackages = llvmPackages;
270
271 meta = with lib; {
272 inherit (binary.meta) platforms;
273 description = "Compiled language with Ruby like syntax and type inference";
274 mainProgram = "crystal";
275 homepage = "https://crystal-lang.org/";
276 license = licenses.asl20;
277 maintainers = with maintainers; [
278 david50407
279 manveru
280 peterhoeg
281 donovanglover
282 ];
283 };
284 });
285in
286rec {
287 binaryCrystal_1_10 = genericBinary {
288 version = "1.10.1";
289 sha256s = {
290 x86_64-linux = "sha256-F0LjdV02U9G6B8ApHxClF/o5KvhxMNukSX7Z2CwSNIs=";
291 aarch64-darwin = "sha256-5kkObQl0VIO6zqQ8TYl0JzYyUmwfmPE9targpfwseSQ=";
292 x86_64-darwin = "sha256-5kkObQl0VIO6zqQ8TYl0JzYyUmwfmPE9targpfwseSQ=";
293 aarch64-linux = "sha256-AzFz+nrU/HJmCL1hbCKXf5ej/uypqV1GJPVLQ4J3778=";
294 };
295 };
296
297 crystal_1_11 = generic {
298 version = "1.11.2";
299 sha256 = "sha256-BBEDWqFtmFUNj0kuGBzv71YHO3KjxV4d2ySTCD4HhLc=";
300 binary = binaryCrystal_1_10;
301 llvmPackages = llvmPackages_15;
302 };
303
304 crystal_1_14 = generic {
305 version = "1.14.1";
306 sha256 = "sha256-cQWK92BfksOW8GmoXn4BmPGJ7CLyLAeKccOffQMh5UU=";
307 binary = binaryCrystal_1_10;
308 llvmPackages = llvmPackages_18;
309 doCheck = false; # Some compiler spec problems on x86-64_linux with the .0 release
310 };
311
312 crystal_1_15 = generic {
313 version = "1.15.1";
314 sha256 = "sha256-L/Q8yZdDq/wn4kJ+zpLfi4pxznAtgjxTCbLnEiCC2K0=";
315 binary = binaryCrystal_1_10;
316 llvmPackages = llvmPackages_18;
317 doCheck = false;
318 };
319
320 crystal = crystal_1_15;
321}