chruby: allow for specifying Rubies to use

This allows the user to specify an attrset of Rubies to use with chruby by
overriding the default of ~/.rubies with a path to a symlink tree.
This commit is contained in:
Charles Strahan 2014-10-27 03:48:30 +00:00
parent 03ee662161
commit a8a9b93d98
3 changed files with 31 additions and 4 deletions

View File

@ -1,6 +1,13 @@
{ stdenv, lib, fetchFromGitHub }:
{ stdenv, lib, fetchFromGitHub, runCommand, rubies ? null }:
stdenv.mkDerivation rec {
let
rubiesEnv = runCommand "chruby-env" { preferLocalBuild = true; } ''
mkdir $out
${lib.concatStrings
(lib.mapAttrsToList (name: path: "ln -s ${path} $out/${name}\n") rubies)}
'';
in stdenv.mkDerivation rec {
name = "chruby";
src = fetchFromGitHub {
@ -10,7 +17,15 @@ stdenv.mkDerivation rec {
sha256 = "1iq9milnnj3189yw02hkly2pnnh4g0vn2fxq6dfx90kldjwpwxq5";
};
phases = [ "unpackPhase" "installPhase" "fixupPhase" ];
phases = [ "unpackPhase" "patchPhase" "installPhase" "fixupPhase" ];
patches = lib.optionalString (rubies != null) [
./env.patch
];
postPatch = lib.optionalString (rubies != null) ''
substituteInPlace share/chruby/chruby.sh --replace "@rubiesEnv@" ${rubiesEnv}
'';
installPhase = ''
mkdir $out

View File

@ -0,0 +1,12 @@
diff --git a/share/chruby/chruby.sh b/share/chruby/chruby.sh
--- a/share/chruby/chruby.sh
+++ b/share/chruby/chruby.sh
@@ -1,7 +1,7 @@
CHRUBY_VERSION="0.3.8"
RUBIES=()
-for dir in "$PREFIX/opt/rubies" "$HOME/.rubies"; do
+for dir in @rubiesEnv@; do
[[ -d "$dir" && -n "$(ls -A "$dir")" ]] && RUBIES+=("$dir"/*)
done
unset dir

View File

@ -4270,7 +4270,7 @@ let
chrpath = callPackage ../development/tools/misc/chrpath { };
chruby = callPackage ../development/tools/misc/chruby { };
chruby = callPackage ../development/tools/misc/chruby { rubies = null; };
"cl-launch" = callPackage ../development/tools/misc/cl-launch {};