forked from crystal-lang/crystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.nix
95 lines (78 loc) · 3.09 KB
/
shell.nix
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# This nix-shell script can be used to get a complete development environment
# for the Crystal compiler.
#
# You can choose which llvm version use and, on Linux, choose to use musl.
#
# $ nix-shell --pure
# $ nix-shell --pure --arg llvm 10
# $ nix-shell --pure --arg llvm 10 --arg musl true
# $ nix-shell --pure --arg llvm 9
# $ nix-shell --pure --arg llvm 9 --argstr system i686-linux
# ...
# $ nix-shell --pure --arg llvm 6
#
# If needed, you can use https://app.cachix.org/cache/crystal-ci to avoid building
# packages that are not available in Nix directly. This is mostly useful for musl.
#
# $ nix-env -iA cachix -f https://cachix.org/api/v1/install
# $ cachix use crystal-ci
# $ nix-shell --pure --arg musl true
#
{llvm ? 11, musl ? false, system ? builtins.currentSystem}:
let
nixpkgs = import (builtins.fetchTarball {
name = "nixpkgs-23.05";
url = "https://github.com/NixOS/nixpkgs/archive/23.05.tar.gz";
sha256 = "10wn0l08j9lgqcw8177nh2ljrnxdrpri7bp0g7nvrsn9rkawvlbf";
}) {
inherit system;
};
pkgs = if musl then nixpkgs.pkgsMusl else nixpkgs;
llvmPackages = pkgs."llvmPackages_${toString llvm}";
genericBinary = { url, sha256 }:
pkgs.stdenv.mkDerivation rec {
name = "crystal-binary";
src = builtins.fetchTarball { inherit url sha256; };
# Extract only the compiler binary
buildCommand = ''
mkdir -p $out/bin
# Darwin packages use embedded/bin/crystal
[ ! -f "${src}/embedded/bin/crystal" ] || cp ${src}/embedded/bin/crystal $out/bin/
# Linux packages use lib/crystal/bin/crystal
[ ! -f "${src}/lib/crystal/bin/crystal" ] || cp ${src}/lib/crystal/bin/crystal $out/bin/
'';
};
# Hashes obtained using `nix-prefetch-url --unpack <url>`
latestCrystalBinary = genericBinary ({
x86_64-darwin = {
url = "https://github.com/crystal-lang/crystal/releases/download/1.14.0/crystal-1.14.0-1-darwin-universal.tar.gz";
sha256 = "sha256:09mp3mngj4wik4v2bffpms3x8dksmrcy0a7hs4cg8b13hrfdrgww";
};
aarch64-darwin = {
url = "https://github.com/crystal-lang/crystal/releases/download/1.14.0/crystal-1.14.0-1-darwin-universal.tar.gz";
sha256 = "sha256:09mp3mngj4wik4v2bffpms3x8dksmrcy0a7hs4cg8b13hrfdrgww";
};
x86_64-linux = {
url = "https://github.com/crystal-lang/crystal/releases/download/1.14.0/crystal-1.14.0-1-linux-x86_64.tar.gz";
sha256 = "sha256:0p5b22ivggf9xlw91cbhib7n4lzd8is1shd3480jjp14rn1kiy5z";
};
}.${pkgs.stdenv.system});
boehmgc = pkgs.boehmgc.override {
enableLargeConfig = true;
};
stdLibDeps = with pkgs; [
boehmgc gmp libevent libiconv libxml2 libyaml openssl pcre2 zlib
] ++ lib.optionals stdenv.isDarwin [ libiconv ];
tools = [ pkgs.hostname pkgs.git llvmPackages.bintools ] ++ pkgs.lib.optional (!llvmPackages.lldb.meta.broken) llvmPackages.lldb;
in
pkgs.stdenv.mkDerivation rec {
name = "crystal-dev";
buildInputs = tools ++ stdLibDeps ++ [
latestCrystalBinary
pkgs.pkg-config
llvmPackages.libllvm
pkgs.libffi
];
LLVM_CONFIG = "${llvmPackages.libllvm.dev}/bin/llvm-config";
MACOSX_DEPLOYMENT_TARGET = "10.11";
}