lol
1{ lib, stdenv, fetchurl, makeFontsConf
2, cacert
3, cairo, coreutils, fontconfig, freefont_ttf
4, glib, gmp
5, gtk3
6, glibcLocales
7, libedit, libffi
8, libiconv
9, libGL
10, libGLU
11, libjpeg
12, ncurses
13, libpng, libtool, mpfr, openssl, pango, poppler
14, readline, sqlite
15, disableDocs ? false
16, CoreFoundation
17, gsettings-desktop-schemas
18, wrapGAppsHook
19}:
20
21let
22
23 fontsConf = makeFontsConf {
24 fontDirectories = [ freefont_ttf ];
25 };
26
27 libPath = lib.makeLibraryPath ([
28 cairo
29 fontconfig
30 glib
31 gmp
32 gtk3
33 gsettings-desktop-schemas
34 libedit
35 libjpeg
36 libpng
37 mpfr
38 ncurses
39 openssl
40 pango
41 poppler
42 readline
43 sqlite
44 ] ++ lib.optionals (!stdenv.isDarwin) [
45 libGL
46 libGLU
47 ]);
48
49in
50
51stdenv.mkDerivation rec {
52 pname = "racket";
53 version = "8.10"; # always change at once with ./minimal.nix
54
55 src = (lib.makeOverridable ({ name, sha256 }:
56 fetchurl {
57 url = "https://mirror.racket-lang.org/installers/${version}/${name}-src.tgz";
58 inherit sha256;
59 }
60 )) {
61 name = "${pname}-${version}";
62 sha256 = "sha256-Dklj2iwX5/bVdCi9odz2Ttp0N+Lya7bMSLR/QXo9k6M=";
63 };
64
65 FONTCONFIG_FILE = fontsConf;
66 LD_LIBRARY_PATH = libPath;
67 NIX_LDFLAGS = lib.concatStringsSep " " [
68 (lib.optionalString (stdenv.cc.isGNU && ! stdenv.isDarwin) "-lgcc_s")
69 ];
70
71 nativeBuildInputs = [ cacert wrapGAppsHook ];
72
73 buildInputs = [ fontconfig libffi libtool sqlite gsettings-desktop-schemas gtk3 ncurses ]
74 ++ lib.optionals stdenv.isDarwin [ libiconv CoreFoundation ];
75
76 patches = [
77 # Hardcode variant detection because we wrap the Racket binary making it
78 # fail to detect its variant at runtime.
79 # See: https://github.com/NixOS/nixpkgs/issues/114993#issuecomment-812951247
80 ./force-cs-variant.patch
81
82 # The entry point binary $out/bin/racket is codesigned at least once. The
83 # following error is triggered as a result.
84 # (error 'add-ad-hoc-signature "file already has a signature")
85 # We always remove the existing signature then call add-ad-hoc-signature to
86 # circumvent this error.
87 ./force-remove-codesign-then-add.patch
88 ];
89
90 preConfigure = ''
91 unset AR
92 for f in src/lt/configure src/cs/c/configure src/bc/src/string.c; do
93 substituteInPlace "$f" \
94 --replace /usr/bin/uname ${coreutils}/bin/uname \
95 --replace /bin/cp ${coreutils}/bin/cp \
96 --replace /bin/ln ${coreutils}/bin/ln \
97 --replace /bin/rm ${coreutils}/bin/rm \
98 --replace /bin/true ${coreutils}/bin/true
99 done
100
101 # The configure script forces using `libtool -o` as AR on Darwin. But, the
102 # `-o` option is only available from Apple libtool. GNU ar works here.
103 substituteInPlace src/ChezScheme/zlib/configure \
104 --replace 'ARFLAGS="-o"' 'AR=ar; ARFLAGS="rc"'
105
106 mkdir src/build
107 cd src/build
108
109 '' + lib.optionalString stdenv.isLinux ''
110 gappsWrapperArgs+=("--prefix" "LD_LIBRARY_PATH" ":" ${libPath})
111 gappsWrapperArgs+=("--set" "LOCALE_ARCHIVE" "${glibcLocales}/lib/locale/locale-archive")
112 '' + lib.optionalString stdenv.isDarwin ''
113 gappsWrapperArgs+=("--prefix" "DYLD_LIBRARY_PATH" ":" ${libPath})
114 ''
115 ;
116
117 preBuild = lib.optionalString stdenv.isDarwin ''
118 # Cannot set DYLD_LIBRARY_PATH as an attr of this drv, becasue dynamic
119 # linker environment variables like this are purged.
120 # See: https://apple.stackexchange.com/a/212954/167199
121
122 # Make builders feed it to dlopen(...). Do not expose all of $libPath to
123 # DYLD_LIBRARY_PATH as the order of looking up symbols like
124 # `__cg_jpeg_resync_to_restart` will be messed up. Our libJPEG.dyllib
125 # expects it from our libTIFF.dylib, but instead it could not be found from
126 # the system `libTIFF.dylib`. DYLD_FALLBACK_LIBRARY_PATH has its own problem
127 # , too.
128 export DYLD_FALLBACK_LIBRARY_PATH="${libPath}"
129 '';
130
131 shared = if stdenv.isDarwin then "dylib" else "shared";
132 configureFlags = [ "--enable-${shared}" "--enable-lt=${libtool}/bin/libtool" ]
133 ++ lib.optionals disableDocs [ "--disable-docs" ]
134 ++ lib.optionals stdenv.isDarwin [ "--disable-strip" "--enable-xonx" ];
135
136 configureScript = "../configure";
137
138 enableParallelBuilding = false;
139
140 meta = with lib; {
141 description = "A programmable programming language";
142 longDescription = ''
143 Racket is a full-spectrum programming language. It goes beyond
144 Lisp and Scheme with dialects that support objects, types,
145 laziness, and more. Racket enables programmers to link
146 components written in different dialects, and it empowers
147 programmers to create new, project-specific dialects. Racket's
148 libraries support applications from web servers and databases to
149 GUIs and charts.
150 '';
151 homepage = "https://racket-lang.org/";
152 changelog = "https://github.com/racket/racket/releases/tag/v${version}";
153 license = with licenses; [ asl20 /* or */ mit ];
154 maintainers = with maintainers; [ henrytill vrthra ];
155 platforms = [ "x86_64-darwin" "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
156 };
157}