Skip to content

Commit

Permalink
Problem: drracket doesn't build
Browse files Browse the repository at this point in the history
There are some circular dependencies in there. They can be made to
work.

The top package is the one that was detected as a circular dependency
by the bottom package and was cut out of the circle. The top package
transitively depends on the rest of the circle, the others are cut off
at the bottom package.

Here's how we can make this work:

1. Don't run setup on any bottom package.

There are some true circular dependencies in there, that won't work
unless the dependency has had a proper setup and registered its
collections. They can be made to work by doing some extra work in the
top (not necessarily, but we were lucky enough that it was the top --
the circle was only two packages) package:

2a. Remove the bottom package from the config.rktd dependencies.
2b. Install both the top and bottom packages in the top installation
    scope.
2c. Run setup on both.

Solution: To get a starting point to work from, first make some ugly
special cases to solve these specific packages. Work on a generic
solution from here.

htdp-lib and deinprogramm-signature have a true circular dependency
that can be solved by (2) (verified with htdp-lib as top).

racket-doc and drracket have a circular dependency that works by just
doing (1) -- force both to not do any setup for now. The racket-doc
package has a whole drove of circular dependencies with other -doc
packages.

For discussion of next steps, see issue fractalide#38.
  • Loading branch information
clacke committed Feb 27, 2018
1 parent a32914c commit 7dd331e
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions racket2nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
(define never-dependency-names '("racket"))
(define always-build-inputs '("racket"))
(define terminal-package-names '("racket-lib"))
(define remove-dependencies-for-package '#hash(
("htdp-lib" . ("deinprogramm-signature"))))

(define header-template #<<EOM
{ pkgs ? import <nixpkgs> {}
Expand Down Expand Up @@ -44,8 +46,16 @@ stdenv.mkDerivation rec {

buildInputs = [ unzip ~a ];
circularBuildInputs = [ ~a ];
circularBuildInputsStr = stdenv.lib.concatStringsSep " " circularBuildInputs;

unpackPhase = "unzip $src -d $name";
unpackPhase = ''
unzip $src -d $name
case $name in
htdp-lib)
unzip ${_deinprogramm-signature.src} -d deinprogramm-signature
;;
esac
'';

patchPhase = ''
case $name in
Expand Down Expand Up @@ -90,7 +100,7 @@ stdenv.mkDerivation rec {
mkdir -p $out/etc/racket $out/share/racket
sed -e 's|$out|'"$out|g" > $out/etc/racket/config.rktd < $racketConfigPath

remove_deps="${stdenv.lib.concatStringsSep " " circularBuildInputs}"
remove_deps="${circularBuildInputsStr}"
if [[ -n $remove_deps ]]; then
sed -i $(printf -- '-e s/"%s"//g ' $remove_deps) $name/info.rkt
fi
Expand All @@ -105,9 +115,18 @@ stdenv.mkDerivation rec {
find $out/share/racket/collects -type d -exec chmod 755 {} +

# install and link us
if ${racket-cmd} -e "(require pkg/lib) (exit (if (member \"$name\" (installed-pkg-names #:scope (bytes->path (string->bytes/utf-8 \"${_racket-lib.out}/share/racket/pkgs\")))) 1 0))"; then
${raco} pkg install --no-setup --copy --deps fail --fail-fast --scope installation ./$name
${raco} setup --no-user --no-pkg-deps --fail-fast --only --pkgs $name
if ${racket-cmd} -e "(require pkg/lib) (exit (if (member \"$name\" (installed-pkg-names #:scope (bytes->path (string->bytes/utf-8 \"${_racket-lib.out}/share/racket/pkgs\")))) 1 0))" &&
[ -z "${circularBuildInputsStr}" ]; then
install_names=$(for install_info in ./*/info.rkt; do echo ''${install_info%/info.rkt}; done)
${raco} pkg install --no-setup --copy --deps fail --fail-fast --scope installation $install_names
for install_name in $install_names; do
case $install_name in
racket-doc|drracket) ;;
*)
${raco} setup --no-user --no-pkg-deps --fail-fast --only --pkgs ''${install_name#./}
;;
esac
done
fi
find $out/share/racket/collects -lname '${_racket-lib.out}/share/racket/collects/*' -delete
find $out/share/racket/collects -type d -empty -delete
Expand All @@ -116,7 +135,10 @@ stdenv.mkDerivation rec {
EOM
)

(define (derivation name url sha1 dependency-names circular-dependency-names)
(define (derivation name url sha1 raw-dependency-names circular-dependency-names)
(define dependency-names (remove* (hash-ref remove-dependencies-for-package name
(lambda () '()))
raw-dependency-names))
(define build-inputs
(string-join
(append always-build-inputs
Expand Down

0 comments on commit 7dd331e

Please sign in to comment.