Starting decomposition of bundlerEnv
This commit is contained in:
parent
ed77e113c5
commit
89fda10d31
134
pkgs/development/ruby-modules/bundler-env/basic.nix
Normal file
134
pkgs/development/ruby-modules/bundler-env/basic.nix
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
{ stdenv, runCommand, ruby, lib
|
||||||
|
, defaultGemConfig, buildRubyGem, buildEnv
|
||||||
|
, makeWrapper
|
||||||
|
, bundler
|
||||||
|
}@defs:
|
||||||
|
|
||||||
|
{
|
||||||
|
drvName
|
||||||
|
, pname
|
||||||
|
, gemfile
|
||||||
|
, lockfile
|
||||||
|
, gemset
|
||||||
|
, ruby ? defs.ruby
|
||||||
|
, gemConfig ? defaultGemConfig
|
||||||
|
, postBuild ? null
|
||||||
|
, document ? []
|
||||||
|
, meta ? {}
|
||||||
|
, groups ? ["default"]
|
||||||
|
, ignoreCollisions ? false
|
||||||
|
, ...
|
||||||
|
}@args:
|
||||||
|
|
||||||
|
with (import ./functions.nix);
|
||||||
|
|
||||||
|
let
|
||||||
|
mainGem = gems."${pname}" or (throw "bundlerEnv: gem ${pname} not found");
|
||||||
|
|
||||||
|
importedGemset = import gemset;
|
||||||
|
|
||||||
|
filteredGemset = lib.filterAttrs (name: attrs: platformMatches attrs && groupMatches attrs) importedGemset;
|
||||||
|
|
||||||
|
configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs:
|
||||||
|
applyGemConfigs (attrs // { inherit ruby; gemName = name; })
|
||||||
|
);
|
||||||
|
|
||||||
|
hasBundler = builtins.hasAttr "bundler" filteredGemset;
|
||||||
|
|
||||||
|
bundler =
|
||||||
|
if hasBundler then gems.bundler
|
||||||
|
else defs.bundler.override (attrs: { inherit ruby; });
|
||||||
|
|
||||||
|
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs);
|
||||||
|
|
||||||
|
copyIfBundledByPath = { bundledByPath ? false, ...}@main:
|
||||||
|
(if bundledByPath then ''
|
||||||
|
cp -a ${gemdir}/* $out/
|
||||||
|
'' else ""
|
||||||
|
);
|
||||||
|
|
||||||
|
maybeCopyAll = main: if main == null then "" else copyIfBundledByPath main;
|
||||||
|
|
||||||
|
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
|
||||||
|
# helpful by doing so at run time, causing executables to immediately bail
|
||||||
|
# out. Yes, I'm serious.
|
||||||
|
confFiles = runCommand "gemfile-and-lockfile" {} ''
|
||||||
|
mkdir -p $out
|
||||||
|
${maybeCopyAll mainGem}
|
||||||
|
cp ${gemfile} $out/Gemfile || ls -l $out/Gemfile
|
||||||
|
cp ${lockfile} $out/Gemfile.lock || ls -l $out/Gemfile.lock
|
||||||
|
'';
|
||||||
|
|
||||||
|
buildGem = name: attrs: (
|
||||||
|
let
|
||||||
|
gemAttrs = composeGemAttrs gems name attrs;
|
||||||
|
in
|
||||||
|
if gemAttrs.type == "path" then
|
||||||
|
pathDerivation gemAttrs
|
||||||
|
else
|
||||||
|
buildRubyGem gemAttrs
|
||||||
|
);
|
||||||
|
|
||||||
|
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
|
||||||
|
|
||||||
|
# binPaths = if mainGem != null then [ mainGem ] else envPaths;
|
||||||
|
|
||||||
|
in
|
||||||
|
buildEnv {
|
||||||
|
inherit ignoreCollisions;
|
||||||
|
|
||||||
|
name = drvName;
|
||||||
|
|
||||||
|
paths = envPaths;
|
||||||
|
pathsToLink = [ "/lib" ];
|
||||||
|
|
||||||
|
postBuild = genStubsScript defs // args // {
|
||||||
|
inherit confFiles bundler;
|
||||||
|
binPaths = envPaths;
|
||||||
|
} + lib.optionalString (postBuild != null) postBuild;
|
||||||
|
|
||||||
|
meta = { platforms = ruby.meta.platforms; } // meta;
|
||||||
|
|
||||||
|
passthru = rec {
|
||||||
|
inherit ruby bundler gems;
|
||||||
|
|
||||||
|
wrappedRuby = stdenv.mkDerivation {
|
||||||
|
name = "wrapped-ruby-${drvName}";
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
buildCommand = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
for i in ${ruby}/bin/*; do
|
||||||
|
makeWrapper "$i" $out/bin/$(basename "$i") \
|
||||||
|
--set BUNDLE_GEMFILE ${confFiles}/Gemfile \
|
||||||
|
--set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \
|
||||||
|
--set BUNDLE_FROZEN 1 \
|
||||||
|
--set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \
|
||||||
|
--set GEM_PATH ${bundlerEnv}/${ruby.gemPath}
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
env = let
|
||||||
|
irbrc = builtins.toFile "irbrc" ''
|
||||||
|
if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?)
|
||||||
|
require ENV["OLD_IRBRC"]
|
||||||
|
end
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler/setup'
|
||||||
|
'';
|
||||||
|
in stdenv.mkDerivation {
|
||||||
|
name = "${drvName}-interactive-environment";
|
||||||
|
nativeBuildInputs = [ wrappedRuby bundlerEnv ];
|
||||||
|
shellHook = ''
|
||||||
|
export OLD_IRBRC="$IRBRC"
|
||||||
|
export IRBRC=${irbrc}
|
||||||
|
'';
|
||||||
|
buildCommand = ''
|
||||||
|
echo >&2 ""
|
||||||
|
echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
|
||||||
|
echo >&2 ""
|
||||||
|
exit 1
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
|
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
|
||||||
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
|
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
|
||||||
|
, linkFarm
|
||||||
, git
|
, git
|
||||||
, makeWrapper
|
, makeWrapper
|
||||||
, bundler
|
, bundler
|
||||||
@ -12,7 +13,6 @@
|
|||||||
, gemfile ? null
|
, gemfile ? null
|
||||||
, lockfile ? null
|
, lockfile ? null
|
||||||
, gemset ? null
|
, gemset ? null
|
||||||
, allBins ? false
|
|
||||||
, ruby ? defs.ruby
|
, ruby ? defs.ruby
|
||||||
, gemConfig ? defaultGemConfig
|
, gemConfig ? defaultGemConfig
|
||||||
, postBuild ? null
|
, postBuild ? null
|
||||||
@ -45,151 +45,26 @@ let
|
|||||||
if gemset == null then gemdir + "/gemset.nix"
|
if gemset == null then gemdir + "/gemset.nix"
|
||||||
else gemset;
|
else gemset;
|
||||||
|
|
||||||
importedGemset = import gemset';
|
|
||||||
|
|
||||||
platformMatches = attrs: (
|
|
||||||
!(attrs ? "platforms") ||
|
|
||||||
builtins.any (platform:
|
|
||||||
platform.engine == ruby.rubyEngine &&
|
|
||||||
(!(platform ? "version") || platform.version == ruby.version.majMin)
|
|
||||||
) attrs.platforms
|
|
||||||
);
|
|
||||||
|
|
||||||
groupMatches = attrs: (
|
|
||||||
!(attrs ? "groups") ||
|
|
||||||
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
|
|
||||||
);
|
|
||||||
|
|
||||||
filteredGemset = lib.filterAttrs (name: attrs: platformMatches attrs && groupMatches attrs) importedGemset;
|
|
||||||
|
|
||||||
applyGemConfigs = attrs:
|
|
||||||
(if gemConfig ? "${attrs.gemName}"
|
|
||||||
then attrs // gemConfig."${attrs.gemName}" attrs
|
|
||||||
else attrs);
|
|
||||||
|
|
||||||
configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs:
|
|
||||||
applyGemConfigs (attrs // { inherit ruby; gemName = name; })
|
|
||||||
);
|
|
||||||
|
|
||||||
hasBundler = builtins.hasAttr "bundler" filteredGemset;
|
|
||||||
|
|
||||||
bundler =
|
|
||||||
if hasBundler then gems.bundler
|
|
||||||
else defs.bundler.override (attrs: { inherit ruby; });
|
|
||||||
|
|
||||||
pathDerivation = { gemName, version, path, ... }:
|
|
||||||
let
|
|
||||||
res = {
|
|
||||||
type = "derivation";
|
|
||||||
bundledByPath = true;
|
|
||||||
name = gemName;
|
|
||||||
version = version;
|
|
||||||
outPath = path;
|
|
||||||
outputs = [ "out" ];
|
|
||||||
out = res;
|
|
||||||
outputName = "out";
|
|
||||||
};
|
|
||||||
in res;
|
|
||||||
|
|
||||||
buildGem = name: attrs: (
|
|
||||||
let
|
|
||||||
gemAttrs = ((removeAttrs attrs ["source"]) // attrs.source // {
|
|
||||||
inherit ruby;
|
|
||||||
gemName = name;
|
|
||||||
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
|
|
||||||
});
|
|
||||||
in
|
|
||||||
if gemAttrs.type == "path" then pathDerivation gemAttrs
|
|
||||||
else buildRubyGem gemAttrs);
|
|
||||||
|
|
||||||
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs);
|
|
||||||
|
|
||||||
maybeCopyAll = main: if main == null then "" else copyIfBundledByPath main;
|
|
||||||
|
|
||||||
copyIfBundledByPath = { bundledByPath ? false, ...}@main:
|
|
||||||
(if bundledByPath then ''
|
|
||||||
cp -a ${gemdir}/* $out/
|
|
||||||
'' else ""
|
|
||||||
);
|
|
||||||
|
|
||||||
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
|
|
||||||
# helpful by doing so at run time, causing executables to immediately bail
|
|
||||||
# out. Yes, I'm serious.
|
|
||||||
confFiles = runCommand "gemfile-and-lockfile" {} ''
|
|
||||||
mkdir -p $out
|
|
||||||
${maybeCopyAll mainGem}
|
|
||||||
cp ${gemfile'} $out/Gemfile || ls -l $out/Gemfile
|
|
||||||
cp ${lockfile'} $out/Gemfile.lock || ls -l $out/Gemfile.lock
|
|
||||||
'';
|
|
||||||
|
|
||||||
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
|
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
|
||||||
|
|
||||||
binPaths = if !allBins && mainGem != null then [ mainGem ] else envPaths;
|
binPaths = if mainGem != null then [ mainGem ] else envPaths;
|
||||||
|
|
||||||
genStubs = binPaths: ''
|
basicEnv = import ./basic args // { inherit drvName pname gemfile lockfile gemset; };
|
||||||
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
|
|
||||||
"${ruby}/bin/ruby" \
|
|
||||||
"${confFiles}/Gemfile" \
|
|
||||||
"$out/${ruby.gemPath}" \
|
|
||||||
"${bundler}/${ruby.gemPath}" \
|
|
||||||
${lib.escapeShellArg binPaths} \
|
|
||||||
${lib.escapeShellArg groups}
|
|
||||||
'';
|
|
||||||
|
|
||||||
bundlerEnv = buildEnv {
|
# Idea here is a mkDerivation that gen-bin-stubs new stubs "as specified" -
|
||||||
inherit ignoreCollisions;
|
# either specific executables or the bin/ for certain gem(s), but
|
||||||
|
# incorporates the basicEnv as a requirement so that its $out is in our path.
|
||||||
|
|
||||||
name = drvName;
|
# When stubbing the bins for a gem, we should use the gem expression
|
||||||
|
# directly, which means that basicEnv should somehow make it available.
|
||||||
|
|
||||||
paths = envPaths;
|
# Different use cases should use different variations on this file, rather
|
||||||
pathsToLink = [ "/lib" ];
|
# than the expression trying to deduce a use case.
|
||||||
|
|
||||||
postBuild = (genStubs binPaths) + lib.optionalString (postBuild != null) postBuild;
|
# The basicEnv should be put into passthru so that e.g. nix-shell can use it.
|
||||||
|
|
||||||
meta = { platforms = ruby.meta.platforms; } // meta;
|
|
||||||
|
|
||||||
passthru = rec {
|
|
||||||
inherit ruby bundler gems;
|
|
||||||
|
|
||||||
wrappedRuby = stdenv.mkDerivation {
|
|
||||||
name = "wrapped-ruby-${drvName}";
|
|
||||||
nativeBuildInputs = [ makeWrapper ];
|
|
||||||
buildCommand = ''
|
|
||||||
mkdir -p $out/bin
|
|
||||||
for i in ${ruby}/bin/*; do
|
|
||||||
makeWrapper "$i" $out/bin/$(basename "$i") \
|
|
||||||
--set BUNDLE_GEMFILE ${confFiles}/Gemfile \
|
|
||||||
--set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \
|
|
||||||
--set BUNDLE_FROZEN 1 \
|
|
||||||
--set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \
|
|
||||||
--set GEM_PATH ${bundlerEnv}/${ruby.gemPath}
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
env = let
|
|
||||||
irbrc = builtins.toFile "irbrc" ''
|
|
||||||
if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?)
|
|
||||||
require ENV["OLD_IRBRC"]
|
|
||||||
end
|
|
||||||
require 'rubygems'
|
|
||||||
require 'bundler/setup'
|
|
||||||
'';
|
|
||||||
in stdenv.mkDerivation {
|
|
||||||
name = "${drvName}-interactive-environment";
|
|
||||||
nativeBuildInputs = [ wrappedRuby bundlerEnv ];
|
|
||||||
shellHook = ''
|
|
||||||
export OLD_IRBRC="$IRBRC"
|
|
||||||
export IRBRC=${irbrc}
|
|
||||||
'';
|
|
||||||
buildCommand = ''
|
|
||||||
echo >&2 ""
|
|
||||||
echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
|
|
||||||
echo >&2 ""
|
|
||||||
exit 1
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
bundlerEnv
|
(linkFarm drvName entries) // {
|
||||||
|
passthru = {
|
||||||
|
inherit basicEnv;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
49
pkgs/development/ruby-modules/bundler-env/functions.nix
Normal file
49
pkgs/development/ruby-modules/bundler-env/functions.nix
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
rec {
|
||||||
|
platformMatches = attrs: (
|
||||||
|
!(attrs ? "platforms") ||
|
||||||
|
builtins.any (platform:
|
||||||
|
platform.engine == ruby.rubyEngine &&
|
||||||
|
(!(platform ? "version") || platform.version == ruby.version.majMin)
|
||||||
|
) attrs.platforms
|
||||||
|
);
|
||||||
|
|
||||||
|
groupMatches = attrs: (
|
||||||
|
!(attrs ? "groups") ||
|
||||||
|
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
|
||||||
|
);
|
||||||
|
|
||||||
|
applyGemConfigs = attrs:
|
||||||
|
(if gemConfig ? "${attrs.gemName}"
|
||||||
|
then attrs // gemConfig."${attrs.gemName}" attrs
|
||||||
|
else attrs);
|
||||||
|
|
||||||
|
genStubsScript = { lib, ruby, confFile, bundler, groups, binPaths }@args: ''
|
||||||
|
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
|
||||||
|
"${ruby}/bin/ruby" \
|
||||||
|
"${confFiles}/Gemfile" \
|
||||||
|
"$out/${ruby.gemPath}" \
|
||||||
|
"${bundler}/${ruby.gemPath}" \
|
||||||
|
${lib.escapeShellArg binPaths} \
|
||||||
|
${lib.escapeShellArg groups}
|
||||||
|
'';
|
||||||
|
|
||||||
|
pathDerivation = { gemName, version, path, ... }:
|
||||||
|
let
|
||||||
|
res = {
|
||||||
|
type = "derivation";
|
||||||
|
bundledByPath = true;
|
||||||
|
name = gemName;
|
||||||
|
version = version;
|
||||||
|
outPath = path;
|
||||||
|
outputs = [ "out" ];
|
||||||
|
out = res;
|
||||||
|
outputName = "out";
|
||||||
|
};
|
||||||
|
in res;
|
||||||
|
|
||||||
|
composeGemAttrs = gems: name: attrs: ((removeAttrs attrs ["source"]) // attrs.source // {
|
||||||
|
inherit ruby;
|
||||||
|
gemName = name;
|
||||||
|
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
|
||||||
|
});
|
||||||
|
}
|
195
pkgs/development/ruby-modules/bundler-env/too-complicated.nix
Normal file
195
pkgs/development/ruby-modules/bundler-env/too-complicated.nix
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
|
||||||
|
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
|
||||||
|
, git
|
||||||
|
, makeWrapper
|
||||||
|
, bundler
|
||||||
|
, tree
|
||||||
|
}@defs:
|
||||||
|
|
||||||
|
{ name ? null
|
||||||
|
, pname ? null
|
||||||
|
, gemdir ? null
|
||||||
|
, gemfile ? null
|
||||||
|
, lockfile ? null
|
||||||
|
, gemset ? null
|
||||||
|
, allBins ? false
|
||||||
|
, ruby ? defs.ruby
|
||||||
|
, gemConfig ? defaultGemConfig
|
||||||
|
, postBuild ? null
|
||||||
|
, document ? []
|
||||||
|
, meta ? {}
|
||||||
|
, groups ? ["default"]
|
||||||
|
, ignoreCollisions ? false
|
||||||
|
, ...
|
||||||
|
}@args:
|
||||||
|
|
||||||
|
let
|
||||||
|
drvName =
|
||||||
|
if name != null then name
|
||||||
|
else if pname != null then "${toString pname}-${mainGem.version}"
|
||||||
|
else throw "bundlerEnv: either pname or name must be set";
|
||||||
|
|
||||||
|
mainGem =
|
||||||
|
if pname == null then null
|
||||||
|
else gems."${pname}" or (throw "bundlerEnv: gem ${pname} not found");
|
||||||
|
|
||||||
|
gemfile' =
|
||||||
|
if gemfile == null then gemdir + "/Gemfile"
|
||||||
|
else gemfile;
|
||||||
|
|
||||||
|
lockfile' =
|
||||||
|
if lockfile == null then gemdir + "/Gemfile.lock"
|
||||||
|
else lockfile;
|
||||||
|
|
||||||
|
gemset' =
|
||||||
|
if gemset == null then gemdir + "/gemset.nix"
|
||||||
|
else gemset;
|
||||||
|
|
||||||
|
importedGemset = import gemset';
|
||||||
|
|
||||||
|
platformMatches = attrs: (
|
||||||
|
!(attrs ? "platforms") ||
|
||||||
|
builtins.any (platform:
|
||||||
|
platform.engine == ruby.rubyEngine &&
|
||||||
|
(!(platform ? "version") || platform.version == ruby.version.majMin)
|
||||||
|
) attrs.platforms
|
||||||
|
);
|
||||||
|
|
||||||
|
groupMatches = attrs: (
|
||||||
|
!(attrs ? "groups") ||
|
||||||
|
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
|
||||||
|
);
|
||||||
|
|
||||||
|
filteredGemset = lib.filterAttrs (name: attrs: platformMatches attrs && groupMatches attrs) importedGemset;
|
||||||
|
|
||||||
|
applyGemConfigs = attrs:
|
||||||
|
(if gemConfig ? "${attrs.gemName}"
|
||||||
|
then attrs // gemConfig."${attrs.gemName}" attrs
|
||||||
|
else attrs);
|
||||||
|
|
||||||
|
configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs:
|
||||||
|
applyGemConfigs (attrs // { inherit ruby; gemName = name; })
|
||||||
|
);
|
||||||
|
|
||||||
|
hasBundler = builtins.hasAttr "bundler" filteredGemset;
|
||||||
|
|
||||||
|
bundler =
|
||||||
|
if hasBundler then gems.bundler
|
||||||
|
else defs.bundler.override (attrs: { inherit ruby; });
|
||||||
|
|
||||||
|
pathDerivation = { gemName, version, path, ... }:
|
||||||
|
let
|
||||||
|
res = {
|
||||||
|
type = "derivation";
|
||||||
|
bundledByPath = true;
|
||||||
|
name = gemName;
|
||||||
|
version = version;
|
||||||
|
outPath = path;
|
||||||
|
outputs = [ "out" ];
|
||||||
|
out = res;
|
||||||
|
outputName = "out";
|
||||||
|
};
|
||||||
|
in res;
|
||||||
|
|
||||||
|
buildGem = name: attrs: (
|
||||||
|
let
|
||||||
|
gemAttrs = ((removeAttrs attrs ["source"]) // attrs.source // {
|
||||||
|
inherit ruby;
|
||||||
|
gemName = name;
|
||||||
|
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
|
||||||
|
});
|
||||||
|
in
|
||||||
|
if gemAttrs.type == "path" then pathDerivation gemAttrs
|
||||||
|
else buildRubyGem gemAttrs);
|
||||||
|
|
||||||
|
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs);
|
||||||
|
|
||||||
|
maybeCopyAll = main: if main == null then "" else copyIfBundledByPath main;
|
||||||
|
|
||||||
|
copyIfBundledByPath = { bundledByPath ? false, ...}@main:
|
||||||
|
(if bundledByPath then ''
|
||||||
|
cp -a ${gemdir}/* $out/
|
||||||
|
'' else ""
|
||||||
|
);
|
||||||
|
|
||||||
|
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
|
||||||
|
# helpful by doing so at run time, causing executables to immediately bail
|
||||||
|
# out. Yes, I'm serious.
|
||||||
|
confFiles = runCommand "gemfile-and-lockfile" {} ''
|
||||||
|
mkdir -p $out
|
||||||
|
${maybeCopyAll mainGem}
|
||||||
|
cp ${gemfile'} $out/Gemfile || ls -l $out/Gemfile
|
||||||
|
cp ${lockfile'} $out/Gemfile.lock || ls -l $out/Gemfile.lock
|
||||||
|
'';
|
||||||
|
|
||||||
|
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
|
||||||
|
|
||||||
|
binPaths = if !allBins && mainGem != null then [ mainGem ] else envPaths;
|
||||||
|
|
||||||
|
genStubs = binPaths: ''
|
||||||
|
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
|
||||||
|
"${ruby}/bin/ruby" \
|
||||||
|
"${confFiles}/Gemfile" \
|
||||||
|
"$out/${ruby.gemPath}" \
|
||||||
|
"${bundler}/${ruby.gemPath}" \
|
||||||
|
${lib.escapeShellArg binPaths} \
|
||||||
|
${lib.escapeShellArg groups}
|
||||||
|
'';
|
||||||
|
|
||||||
|
bundlerEnv = buildEnv {
|
||||||
|
inherit ignoreCollisions;
|
||||||
|
|
||||||
|
name = drvName;
|
||||||
|
|
||||||
|
paths = envPaths;
|
||||||
|
pathsToLink = [ "/lib" ];
|
||||||
|
|
||||||
|
postBuild = (genStubs binPaths) + lib.optionalString (postBuild != null) postBuild;
|
||||||
|
|
||||||
|
meta = { platforms = ruby.meta.platforms; } // meta;
|
||||||
|
|
||||||
|
passthru = rec {
|
||||||
|
inherit ruby bundler gems;
|
||||||
|
|
||||||
|
wrappedRuby = stdenv.mkDerivation {
|
||||||
|
name = "wrapped-ruby-${drvName}";
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
buildCommand = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
for i in ${ruby}/bin/*; do
|
||||||
|
makeWrapper "$i" $out/bin/$(basename "$i") \
|
||||||
|
--set BUNDLE_GEMFILE ${confFiles}/Gemfile \
|
||||||
|
--set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \
|
||||||
|
--set BUNDLE_FROZEN 1 \
|
||||||
|
--set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \
|
||||||
|
--set GEM_PATH ${bundlerEnv}/${ruby.gemPath}
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
env = let
|
||||||
|
irbrc = builtins.toFile "irbrc" ''
|
||||||
|
if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?)
|
||||||
|
require ENV["OLD_IRBRC"]
|
||||||
|
end
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler/setup'
|
||||||
|
'';
|
||||||
|
in stdenv.mkDerivation {
|
||||||
|
name = "${drvName}-interactive-environment";
|
||||||
|
nativeBuildInputs = [ wrappedRuby bundlerEnv ];
|
||||||
|
shellHook = ''
|
||||||
|
export OLD_IRBRC="$IRBRC"
|
||||||
|
export IRBRC=${irbrc}
|
||||||
|
'';
|
||||||
|
buildCommand = ''
|
||||||
|
echo >&2 ""
|
||||||
|
echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
|
||||||
|
echo >&2 ""
|
||||||
|
exit 1
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
bundlerEnv
|
Loading…
x
Reference in New Issue
Block a user