From e927eba03b4161ce9ca8ec1a495ff1431daf0d64 Mon Sep 17 00:00:00 2001 From: rczb Date: Mon, 20 Jan 2025 22:54:46 +0800 Subject: [PATCH 1/3] racket and racket-minimal: separate recipes --- .../interpreters/racket/default.nix | 242 +++++------------- .../interpreters/racket/minimal.nix | 172 +++++++++++++ pkgs/top-level/all-packages.nix | 2 +- 3 files changed, 238 insertions(+), 178 deletions(-) create mode 100644 pkgs/development/interpreters/racket/minimal.nix diff --git a/pkgs/development/interpreters/racket/default.nix b/pkgs/development/interpreters/racket/default.nix index b5c40f363e3f..adefea1dd036 100644 --- a/pkgs/development/interpreters/racket/default.nix +++ b/pkgs/development/interpreters/racket/default.nix @@ -2,15 +2,10 @@ lib, stdenv, fetchurl, + racket-minimal, - libiconvReal, - libz, - lz4, - ncurses, openssl, - isMinimal ? false, - cairo, fontconfig, glib, @@ -29,10 +24,11 @@ disableDocs ? false, callPackage, - writers, }: let + minimal = racket-minimal.override { inherit disableDocs; }; + makeLibPaths = lib.concatMapStringsSep " " ( lib.flip lib.pipe [ lib.getLib @@ -41,9 +37,12 @@ let ); manifest = lib.importJSON ./manifest.json; - inherit (stdenv.hostPlatform) isDarwin isStatic; + inherit (stdenv.hostPlatform) isDarwin; + + runtimeDeps = [ + openssl + ]; - runtimeDeps = [ openssl ]; mainDistDeps = [ (if isDarwin then libiodbc else unixODBC) cairo @@ -58,83 +57,22 @@ let ]; in -stdenv.mkDerivation (finalAttrs: { - pname = "racket"; - inherit (manifest) version; - - src = - let - info = manifest.${if isMinimal then "minimal" else "full"}; - in - fetchurl { - url = "https://mirror.racket-lang.org/installers/${manifest.version}/${info.filename}"; - inherit (info) sha256; +minimal.overrideAttrs ( + finalAttrs: prevAttrs: { + src = fetchurl { + url = "https://mirror.racket-lang.org/installers/${manifest.version}/${manifest.full.filename}"; + inherit (manifest.full) sha256; }; - nativeBuildInputs = lib.optionals (!isMinimal) [ - wrapGAppsHook3 - ]; - - buildInputs = [ - libiconvReal - libz - lz4 - ncurses - ]; - - patches = lib.optionals isDarwin [ - /* - The entry point binary $out/bin/racket is codesigned at least once. The - following error is triggered as a result. - (error 'add-ad-hoc-signature "file already has a signature") - We always remove the existing signature then call add-ad-hoc-signature to - circumvent this error. - */ - ./patches/force-remove-codesign-then-add.patch - ]; - - preConfigure = - /* - The configure script forces using `libtool -o` as AR on Darwin. But, the - `-o` option is only available from Apple libtool. GNU ar works here. - */ - lib.optionalString isDarwin '' - substituteInPlace src/ChezScheme/zlib/configure \ - --replace-fail 'ARFLAGS="-o"' 'AR=ar; ARFLAGS="rc"' - '' - + '' - mkdir src/build - cd src/build - ''; - - configureScript = "../configure"; - - configureFlags = - [ - "--enable-check" - "--enable-csonly" - "--enable-liblz4" - "--enable-libz" - ] - ++ lib.optional disableDocs "--disable-docs" - ++ lib.optionals (!isStatic) [ - # instead of `--disable-static` that `stdenv` assumes - "--disable-libs" - # "not currently supported" in `configure --help-cs` but still emphasized in README - "--enable-shared" - ] - ++ lib.optionals isDarwin [ - "--disable-strip" - # "use Unix style (e.g., use Gtk) for Mac OS", which eliminates many problems - "--enable-xonx" + nativeBuildInputs = [ + wrapGAppsHook3 ]; - preBuild = - let - libPaths = makeLibPaths mainDistDeps; - libPathsVar = if isDarwin then "DYLD_FALLBACK_LIBRARY_PATH" else "LD_LIBRARY_PATH"; - in - lib.optionalString (!isMinimal) ( + preBuild = + let + libPaths = makeLibPaths mainDistDeps; + libPathsVar = if isDarwin then "DYLD_FALLBACK_LIBRARY_PATH" else "LD_LIBRARY_PATH"; + in /* Makes FFIs available for setting up `main-distribution` and its dependencies, which is integrated into the build process of Racket @@ -148,81 +86,50 @@ stdenv.mkDerivation (finalAttrs: { + '' export FONTCONFIG_FILE=${makeFontsConf { fontDirectories = [ ]; }} export XDG_CACHE_HOME=$(mktemp -d) - '' - ); + ''; - dontStrip = isDarwin; - - preFixup = lib.optionalString (!isMinimal && !isDarwin) '' - gappsWrapperArgs+=("--set" "LOCALE_ARCHIVE" "${glibcLocales}/lib/locale/locale-archive") - ''; - - postFixup = - let - libPaths = makeLibPaths (runtimeDeps ++ lib.optionals (!isMinimal) mainDistDeps); - in - '' - $out/bin/racket -f - < Racket is distributed under the MIT license and the Apache version 2.0 - > license, at your option. - - > The Racket runtime system embeds Chez Scheme, which is distributed - > under the Apache version 2.0 license. - */ - license = with lib.licenses; [ - asl20 - mit - ]; - maintainers = with lib.maintainers; [ rc-zb ]; - mainProgram = "racket"; - platforms = lib.platforms.${if isMinimal then "all" else "unix"}; - badPlatforms = lib.platforms.darwin; - }; -}) + platforms = lib.platforms.unix; + badPlatforms = lib.platforms.darwin; + }; + } +) diff --git a/pkgs/development/interpreters/racket/minimal.nix b/pkgs/development/interpreters/racket/minimal.nix new file mode 100644 index 000000000000..c1abd3f983b1 --- /dev/null +++ b/pkgs/development/interpreters/racket/minimal.nix @@ -0,0 +1,172 @@ +{ + lib, + stdenv, + fetchurl, + + libiconvReal, + libz, + lz4, + ncurses, + openssl, + + disableDocs ? false, + + callPackage, + writers, +}: + +let + manifest = lib.importJSON ./manifest.json; + + inherit (stdenv.hostPlatform) isDarwin isStatic; +in + +stdenv.mkDerivation (finalAttrs: { + pname = "racket"; + inherit (manifest) version; + + src = fetchurl { + url = "https://mirror.racket-lang.org/installers/${manifest.version}/${manifest.minimal.filename}"; + inherit (manifest.minimal) sha256; + }; + + buildInputs = [ + libiconvReal + libz + lz4 + ncurses + ]; + + patches = lib.optionals isDarwin [ + /* + The entry point binary $out/bin/racket is codesigned at least once. The + following error is triggered as a result. + (error 'add-ad-hoc-signature "file already has a signature") + We always remove the existing signature then call add-ad-hoc-signature to + circumvent this error. + */ + ./patches/force-remove-codesign-then-add.patch + ]; + + preConfigure = + /* + The configure script forces using `libtool -o` as AR on Darwin. But, the + `-o` option is only available from Apple libtool. GNU ar works here. + */ + lib.optionalString isDarwin '' + substituteInPlace src/ChezScheme/zlib/configure \ + --replace-fail 'ARFLAGS="-o"' 'AR=ar; ARFLAGS="rc"' + '' + + '' + mkdir src/build + cd src/build + ''; + + configureScript = "../configure"; + + configureFlags = + [ + "--enable-check" + "--enable-csonly" + "--enable-liblz4" + "--enable-libz" + ] + ++ lib.optional disableDocs "--disable-docs" + ++ lib.optionals (!isStatic) [ + # instead of `--disable-static` that `stdenv` assumes + "--disable-libs" + # "not currently supported" in `configure --help-cs` but still emphasized in README + "--enable-shared" + ] + ++ lib.optionals isDarwin [ + "--disable-strip" + # "use Unix style (e.g., use Gtk) for Mac OS", which eliminates many problems + "--enable-xonx" + ]; + + dontStrip = isDarwin; + + postFixup = '' + $out/bin/racket -f - < Racket is distributed under the MIT license and the Apache version 2.0 + > license, at your option. + + > The Racket runtime system embeds Chez Scheme, which is distributed + > under the Apache version 2.0 license. + */ + license = with lib.licenses; [ + asl20 + mit + ]; + maintainers = with lib.maintainers; [ rc-zb ]; + mainProgram = "racket"; + platforms = lib.platforms.all; + badPlatforms = lib.platforms.darwin; + }; +}) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index aa6cdc64dc4f..ab1b2c3e64f4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7285,7 +7285,7 @@ with pkgs; wireplumber = callPackage ../development/libraries/pipewire/wireplumber.nix { }; racket = callPackage ../development/interpreters/racket { }; - racket-minimal = racket.override { isMinimal = true; }; + racket-minimal = callPackage ../development/interpreters/racket/minimal.nix { }; rakudo = callPackage ../development/interpreters/rakudo { }; moarvm = darwin.apple_sdk_11_0.callPackage ../development/interpreters/rakudo/moarvm.nix { From 9f953c133d4ba0608f9b0bee2b5b1aa66a67d258 Mon Sep 17 00:00:00 2001 From: rczb Date: Wed, 22 Jan 2025 11:43:53 +0800 Subject: [PATCH 2/3] racket-minimal: fix docs failure for lack of SQLite --- .../racket/configure-installation.rkt | 27 +++++++++ .../interpreters/racket/default.nix | 55 +++++-------------- .../interpreters/racket/minimal.nix | 29 +++++----- 3 files changed, 53 insertions(+), 58 deletions(-) create mode 100644 pkgs/development/interpreters/racket/configure-installation.rkt diff --git a/pkgs/development/interpreters/racket/configure-installation.rkt b/pkgs/development/interpreters/racket/configure-installation.rkt new file mode 100644 index 000000000000..ffc72b14d243 --- /dev/null +++ b/pkgs/development/interpreters/racket/configure-installation.rkt @@ -0,0 +1,27 @@ +#lang racket/base +(require + racket/function + racket/list + racket/pretty + racket/string + setup/dirs + ) + +(define config-file (build-path (find-config-dir) "config.rktd")) + +(define lib-paths + ((compose remove-duplicates + (curry map (curryr string-trim "-L" #:right? #f)) + (curry filter (curryr string-prefix? "-L")) + string-split) + (getenv "NIX_LDFLAGS"))) + +(define config + (let* ([prev-config (read-installation-configuration-table)] + [prev-lib-search-dirs (hash-ref prev-config 'lib-search-dirs '(#f))] + [lib-search-dirs (remove-duplicates (append lib-paths prev-lib-search-dirs))]) + (hash-set prev-config 'lib-search-dirs lib-search-dirs))) + +(call-with-output-file config-file + #:exists 'replace + (curry pretty-write config)) diff --git a/pkgs/development/interpreters/racket/default.nix b/pkgs/development/interpreters/racket/default.nix index adefea1dd036..2f624f400611 100644 --- a/pkgs/development/interpreters/racket/default.nix +++ b/pkgs/development/interpreters/racket/default.nix @@ -4,8 +4,6 @@ fetchurl, racket-minimal, - openssl, - cairo, fontconfig, glib, @@ -17,7 +15,6 @@ libpng, makeFontsConf, pango, - sqlite, unixODBC, wrapGAppsHook3, @@ -38,23 +35,6 @@ let manifest = lib.importJSON ./manifest.json; inherit (stdenv.hostPlatform) isDarwin; - - runtimeDeps = [ - openssl - ]; - - mainDistDeps = [ - (if isDarwin then libiodbc else unixODBC) - cairo - fontconfig - glib - gtk3 - libGL - libjpeg - libpng - pango - sqlite - ]; in minimal.overrideAttrs ( @@ -64,13 +44,25 @@ minimal.overrideAttrs ( inherit (manifest.full) sha256; }; + buildInputs = prevAttrs.buildInputs ++ [ + (if isDarwin then libiodbc else unixODBC) + cairo + fontconfig.lib + glib + gtk3 + libGL + libjpeg + libpng + pango + ]; + nativeBuildInputs = [ wrapGAppsHook3 ]; preBuild = let - libPaths = makeLibPaths mainDistDeps; + libPaths = makeLibPaths finalAttrs.buildInputs; libPathsVar = if isDarwin then "DYLD_FALLBACK_LIBRARY_PATH" else "LD_LIBRARY_PATH"; in /* @@ -92,27 +84,6 @@ minimal.overrideAttrs ( gappsWrapperArgs+=("--set" "LOCALE_ARCHIVE" "${glibcLocales}/lib/locale/locale-archive") ''; - postFixup = - let - libPaths = makeLibPaths (runtimeDeps ++ mainDistDeps); - in - '' - $out/bin/racket -f - < Date: Thu, 30 Jan 2025 22:39:54 +0800 Subject: [PATCH 3/3] racket: fix failure to find executable Fix #377763. --- .../interpreters/racket/default.nix | 9 +++ .../racket/patches/force-cs-variant.patch | 12 ++++ .../racket/tests/get-version-and-variant.nix | 58 ++++++++++++------- 3 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 pkgs/development/interpreters/racket/patches/force-cs-variant.patch diff --git a/pkgs/development/interpreters/racket/default.nix b/pkgs/development/interpreters/racket/default.nix index 2f624f400611..45ee63f0ec7e 100644 --- a/pkgs/development/interpreters/racket/default.nix +++ b/pkgs/development/interpreters/racket/default.nix @@ -60,6 +60,15 @@ minimal.overrideAttrs ( wrapGAppsHook3 ]; + patches = prevAttrs.patches or [ ] ++ [ + /* + Hardcode variant detection because nixpkgs wraps the Racket binary making it + fail to detect its variant at runtime. + https://github.com/NixOS/nixpkgs/issues/114993#issuecomment-812951247 + */ + ./patches/force-cs-variant.patch + ]; + preBuild = let libPaths = makeLibPaths finalAttrs.buildInputs; diff --git a/pkgs/development/interpreters/racket/patches/force-cs-variant.patch b/pkgs/development/interpreters/racket/patches/force-cs-variant.patch new file mode 100644 index 000000000000..52bb537a1f06 --- /dev/null +++ b/pkgs/development/interpreters/racket/patches/force-cs-variant.patch @@ -0,0 +1,12 @@ +--- old/collects/setup/variant.rkt ++++ new/collects/setup/variant.rkt +@@ -7,7 +7,8 @@ + (provide variant-suffix + script-variant?) + +-(define plain-variant ++(define plain-variant 'cs) ++#;(define plain-variant + (delay/sync + (cond + [(cross-installation?) diff --git a/pkgs/development/interpreters/racket/tests/get-version-and-variant.nix b/pkgs/development/interpreters/racket/tests/get-version-and-variant.nix index c81cb7719380..870542f8f6c0 100644 --- a/pkgs/development/interpreters/racket/tests/get-version-and-variant.nix +++ b/pkgs/development/interpreters/racket/tests/get-version-and-variant.nix @@ -1,27 +1,45 @@ -{ runCommandLocal, racket }: +{ + lib, + runCommandLocal, + racket, +}: runCommandLocal "racket-test-get-version-and-variant" { nativeBuildInputs = [ racket ]; } - '' - expectation="${racket.version}" + ( + lib.concatLines ( + builtins.map + ( + { expectation, output }: + '' + expectation="${expectation}" - output="$(racket -e '(display (version))')" + output="${output}" - if test "$output" != "$expectation"; then - echo "output mismatch: expected ''${expectation}, but got ''${output}" - exit 1 - fi - - expectation="cs" - - output="$(racket -e '(require launcher/launcher) (display (current-launcher-variant))')" - - if test "$output" != "$expectation"; then - echo "output mismatch: expected ''${expectation}, but got ''${output}" - exit 1 - fi - - touch $out - '' + if test "$output" != "$expectation"; then + echo "output mismatch: expected ''${expectation}, but got ''${output}" + exit 1 + fi + '' + ) + [ + { + expectation = racket.version; + output = "$(racket -e '(display (version))')"; + } + { + expectation = "cs"; + output = "$(racket -e '(require launcher/launcher) (display (current-launcher-variant))')"; + } + { + expectation = "${lib.getExe racket}"; + output = "$(racket -e '(require compiler/find-exe) (display (find-exe))')"; + } + ] + ) + + '' + touch $out + '' + )