summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/build-support/fetchegg/builder.sh9
-rw-r--r--pkgs/build-support/fetchegg/default.nix28
-rw-r--r--pkgs/development/compilers/chicken/0001-Introduce-CHICKEN_REPOSITORY_EXTRA.patch130
-rw-r--r--pkgs/development/compilers/chicken/default.nix13
-rw-r--r--pkgs/development/compilers/chicken/eggDerivation.nix40
-rw-r--r--pkgs/development/compilers/chicken/setup-hook.sh7
-rw-r--r--pkgs/top-level/all-packages.nix4
7 files changed, 228 insertions, 3 deletions
diff --git a/pkgs/build-support/fetchegg/builder.sh b/pkgs/build-support/fetchegg/builder.sh
new file mode 100644
index 00000000000..20466106309
--- /dev/null
+++ b/pkgs/build-support/fetchegg/builder.sh
@@ -0,0 +1,9 @@
+source $stdenv/setup
+
+header "exporting egg ${eggName} (version $version) into $out"
+
+mkdir -p $out
+chicken-install -r "${eggName}:${version}"
+cp -r ${eggName}/* $out/
+
+stopNest
diff --git a/pkgs/build-support/fetchegg/default.nix b/pkgs/build-support/fetchegg/default.nix
new file mode 100644
index 00000000000..223d2098c77
--- /dev/null
+++ b/pkgs/build-support/fetchegg/default.nix
@@ -0,0 +1,28 @@
+# Fetches a chicken egg from henrietta using `chicken-install -r'
+# See: http://wiki.call-cc.org/chicken-projects/egg-index-4.html
+
+{ stdenv, chicken }:
+{ name, version, md5 ? "", sha256 ? "" }:
+
+stdenv.mkDerivation {
+  name = "chicken-${name}-export";
+  builder = ./builder.sh;
+  buildInputs = [ chicken ];
+
+  outputHashAlgo = if sha256 == "" then "md5" else "sha256";
+  outputHashMode = "recursive";
+  outputHash = if sha256 == "" then md5 else sha256;
+
+  inherit version;
+
+  eggName = name;
+
+  impureEnvVars = [
+    # We borrow these environment variables from the caller to allow
+    # easy proxy configuration.  This is impure, but a fixed-output
+    # derivation like fetchurl is allowed to do so since its result is
+    # by definition pure.
+    "http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
+  ];
+}
+
diff --git a/pkgs/development/compilers/chicken/0001-Introduce-CHICKEN_REPOSITORY_EXTRA.patch b/pkgs/development/compilers/chicken/0001-Introduce-CHICKEN_REPOSITORY_EXTRA.patch
new file mode 100644
index 00000000000..0962c9cf46d
--- /dev/null
+++ b/pkgs/development/compilers/chicken/0001-Introduce-CHICKEN_REPOSITORY_EXTRA.patch
@@ -0,0 +1,130 @@
+From 752dff853186dc334c519a86fa92f087795fea02 Mon Sep 17 00:00:00 2001
+From: Moritz Heidkamp <moritz.heidkamp@bevuta.com>
+Date: Wed, 1 Oct 2014 22:41:30 +0200
+Subject: [PATCH] Introduce CHICKEN_REPOSITORY_EXTRA
+
+This environment variable works like CHICKEN_REPOSITORY but supports
+multiple paths separated by `:'. Those paths are searched after
+CHICKEN_REPOSITORY when loading extensions via `require-library' and
+friends. It can be accessed and changed at runtime via the new procedure
+`repository-extra-paths' which is analog to `repository-path'.
+---
+ chicken-install.scm | 11 +++++++----
+ chicken.import.scm  |  1 +
+ eval.scm            | 37 +++++++++++++++++++++++++++++++------
+ 3 files changed, 39 insertions(+), 10 deletions(-)
+
+diff --git a/chicken-install.scm b/chicken-install.scm
+index 2ef6ef4..b5c6bf8 100644
+--- a/chicken-install.scm
++++ b/chicken-install.scm
+@@ -109,10 +109,10 @@
+   (define *show-foreign-depends* #f)
+   (define *hacks* '())
+ 
+-  (define (repo-path)
++  (define (repo-paths)
+     (if (and *cross-chicken* (not *host-extension*))
+-	(make-pathname C_TARGET_LIB_HOME (sprintf "chicken/~a" C_BINARY_VERSION))
+-	(repository-path)))
++	(list (make-pathname C_TARGET_LIB_HOME (sprintf "chicken/~a" C_BINARY_VERSION)))
++	(cons (repository-path) (repository-extra-paths))))
+ 
+   (define (get-prefix #!optional runtime)
+     (cond ((and *cross-chicken*
+@@ -757,7 +757,10 @@
+ 		  "installed extension has no information about which egg it belongs to"
+ 		  (pathname-file sf))
+ 		 #f))))
+-      (glob (make-pathname (repo-path) "*" "setup-info")))
++      (append-map
++       (lambda (path)
++	 (glob (make-pathname path "*" "setup-info")))
++       (repo-paths)))
+      equal?))
+ 
+   (define (list-available-extensions trans locn)
+diff --git a/chicken.import.scm b/chicken.import.scm
+index baa7316..2839b16 100644
+--- a/chicken.import.scm
++++ b/chicken.import.scm
+@@ -201,6 +201,7 @@
+    repl
+    repl-prompt
+    repository-path
++   repository-extra-paths
+    require
+    reset
+    reset-handler
+diff --git a/eval.scm b/eval.scm
+index bbcd86c..838588d 100644
+--- a/eval.scm
++++ b/eval.scm
+@@ -81,6 +81,7 @@
+ (define-constant source-file-extension ".scm")
+ (define-constant setup-file-extension "setup-info")
+ (define-constant repository-environment-variable "CHICKEN_REPOSITORY")
++(define-constant repository-extra-environment-variable "CHICKEN_REPOSITORY_EXTRA")
+ (define-constant prefix-environment-variable "CHICKEN_PREFIX")
+ 
+ ; these are actually in unit extras, but that is used by default
+@@ -1180,6 +1181,25 @@
+ 
+ (define repository-path ##sys#repository-path)
+ 
++(define ##sys#repository-extra-paths
++  (let* ((repaths (get-environment-variable repository-extra-environment-variable))
++	 (repaths (if repaths
++		      (let ((len (string-length repaths)))
++			(let loop ((i 0) (offset 0) (res '()))
++			  (cond ((> i len)
++				 (reverse res))
++				((or (= i len) (eq? #\: (string-ref repaths i)))
++				 (loop (+ i 1) (+ i 1) (cons (substring repaths offset i) res)))
++				(else
++				 (loop (+ i 1) offset res)))))
++		      '())))
++    (lambda (#!optional val)
++      (if val
++	  (set! repaths val)
++	  repaths))))
++
++(define repository-extra-paths ##sys#repository-extra-paths)
++
+ (define ##sys#setup-mode #f)
+ 
+ (define ##sys#find-extension
+@@ -1197,6 +1217,7 @@
+ 	(let loop ((paths (##sys#append
+ 			   (if ##sys#setup-mode '(".") '())
+ 			   (if rp (list rp) '())
++			   (##sys#repository-extra-paths)
+ 			   (if inc? ##sys#include-pathnames '())
+ 			   (if ##sys#setup-mode '() '("."))) ))
+ 	  (and (pair? paths)
+@@ -1256,12 +1277,16 @@
+ 	[string-append string-append]
+ 	[read read] )
+     (lambda (id loc)
+-      (and-let* ((rp (##sys#repository-path)))
+-	(let* ((p (##sys#canonicalize-extension-path id loc))
+-	       (rpath (string-append rp "/" p ".")) )
+-	  (cond ((file-exists? (string-append rpath setup-file-extension))
+-		 => (cut with-input-from-file <> read) )
+-		(else #f) ) ) ) ) ))
++      (let loop ((rpaths (cons (##sys#repository-path) (##sys#repository-extra-paths))))
++	(and (pair? rpaths)
++	     (let ((rp (car rpaths)))
++	       (if (not rp)
++		   (loop (cdr rpaths))
++		   (let* ((p (##sys#canonicalize-extension-path id loc))
++			  (rpath (string-append rp "/" p ".")) )
++		     (cond ((file-exists? (string-append rpath setup-file-extension))
++			    => (cut with-input-from-file <> read) )
++			   (else (loop (cdr rpaths))) ) )) ))) ) ))
+ 
+ (define (extension-information ext)
+   (##sys#extension-information ext 'extension-information) )
+-- 
+2.1.0
+
diff --git a/pkgs/development/compilers/chicken/default.nix b/pkgs/development/compilers/chicken/default.nix
index 9e2fbc368fc..cac55efd520 100644
--- a/pkgs/development/compilers/chicken/default.nix
+++ b/pkgs/development/compilers/chicken/default.nix
@@ -8,29 +8,34 @@ let
     else if isBSD then "bsd"
     else if isSunOS then "solaris"
     else "linux";               # Should be a sane default
+  lib = stdenv.lib;
 in
 stdenv.mkDerivation {
   name = "chicken-${version}";
 
+  binaryVersion = 7;
+
   src = fetchurl {
     url = "http://code.call-cc.org/releases/4.9.0/chicken-${version}.tar.gz";
     sha256 = "0598mar1qswfd8hva9nqs88zjn02lzkqd8fzdd21dz1nki1prpq4";
   };
 
+  setupHook = lib.ifEnable (bootstrap-chicken != null) ./setup-hook.sh;
+  
   buildFlags = "PLATFORM=${platform} PREFIX=$(out) VARDIR=$(out)/var/lib";
   installFlags = "PLATFORM=${platform} PREFIX=$(out) VARDIR=$(out)/var/lib";
 
   # We need a bootstrap-chicken to regenerate the c-files after
   # applying a patch to add support for CHICKEN_REPOSITORY_EXTRA
-  patches = stdenv.lib.ifEnable (bootstrap-chicken != null) [
+  patches = lib.ifEnable (bootstrap-chicken != null) [
     ./0001-Introduce-CHICKEN_REPOSITORY_EXTRA.patch
   ];
 
-  buildInputs = stdenv.lib.ifEnable (bootstrap-chicken != null) [
+  buildInputs = lib.ifEnable (bootstrap-chicken != null) [
     bootstrap-chicken
   ];
 
-  preBuild = stdenv.lib.ifEnable (bootstrap-chicken != null) ''
+  preBuild = lib.ifEnable (bootstrap-chicken != null) ''
     # Backup the build* files - those are generated from hostname,
     # git-tag, etc. and we don't need/want that
     mkdir -p build-backup
@@ -42,6 +47,8 @@ stdenv.mkDerivation {
     mv build-backup/* .
   '';
 
+  # TODO: Assert csi -R files -p '(pathname-file (repository-path))' == binaryVersion
+
   meta = {
     homepage = http://www.call-cc.org/;
     license = "BSD";
diff --git a/pkgs/development/compilers/chicken/eggDerivation.nix b/pkgs/development/compilers/chicken/eggDerivation.nix
new file mode 100644
index 00000000000..f9a3da83eab
--- /dev/null
+++ b/pkgs/development/compilers/chicken/eggDerivation.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchegg, chicken, makeWrapper }:
+{ name, src
+, buildInputs ? []
+, chickenInstallFlags ? []
+, cscOptions          ? []
+, ...} @ args:
+
+let
+  libPath = "${chicken}/var/lib/chicken/${toString chicken.binaryVersion}/";
+in
+stdenv.mkDerivation ({
+  name = "chicken-${name}";
+  propagatedBuildInputs = buildInputs ++ [ chicken ];
+  propagatedUserEnvPkgs = buildInputs ++ [ chicken ];
+  buildInputs = [ makeWrapper ];
+
+  CSC_OPTIONS = stdenv.lib.concatStringsSep " " cscOptions;
+
+  CHICKEN_REPOSITORY = libPath;
+  CHICKEN_INSTALL_PREFIX = "$out";
+
+  installPhase = ''
+    runHook preInstall
+
+    chicken-install -p $out ${stdenv.lib.concatStringsSep " " chickenInstallFlags}
+
+    runHook postInstall
+  '';
+
+  postInstall = ''
+    for f in $out/bin/*
+    do
+      wrapProgram $f \
+        --set CHICKEN_REPOSITORY $CHICKEN_REPOSITORY \
+        --prefix CHICKEN_REPOSITORY_EXTRA : "$out/lib/chicken/${toString chicken.binaryVersion}/:$CHICKEN_REPOSITORY_EXTRA" \
+        --prefix CHICKEN_INCLUDE_PATH \; \"$CHICKEN_INCLUDE_PATH\;$out/share/\" \
+        --prefix PATH : "$out/bin:$CHICKEN_REPOSITORY_EXTRA:$CHICKEN_REPOSITORY"
+    done
+  '';
+} // (builtins.removeAttrs args ["name" "buildInputs"]))
diff --git a/pkgs/development/compilers/chicken/setup-hook.sh b/pkgs/development/compilers/chicken/setup-hook.sh
new file mode 100644
index 00000000000..8d6b990a7e0
--- /dev/null
+++ b/pkgs/development/compilers/chicken/setup-hook.sh
@@ -0,0 +1,7 @@
+addChickenRepositoryPath() {
+    addToSearchPathWithCustomDelimiter : CHICKEN_REPOSITORY_EXTRA "$1/lib/chicken/7/"
+    # addToSearchPathWithCustomDelimiter \; CHICKEN_INCLUDE_PATH "$1/share/"
+    export CHICKEN_INCLUDE_PATH="$1/share;$CHICKEN_INCLUDE_PATH"
+}
+
+envHooks=(${envHooks[@]} addChickenRepositoryPath)
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 33b9b86e841..8fc0dbe1731 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2791,6 +2791,10 @@ let
 
   bigloo = callPackage ../development/compilers/bigloo { };
 
+  fetchegg = callPackage ../build-support/fetchegg { };
+
+  eggDerivation = callPackage ../development/compilers/chicken/eggDerivation.nix { };
+
   chicken = callPackage ../development/compilers/chicken {
     bootstrap-chicken = chicken.override { bootstrap-chicken = null; }; 
   };