2017-06-11 01:38:49 +01:00
|
|
|
{ lib, stdenv, callPackage, runCommand, ruby }@defs:
|
2017-05-31 17:44:46 +01:00
|
|
|
|
2017-06-26 01:40:22 +01:00
|
|
|
# Use for simple installation of Ruby tools shipped in a Gem.
|
|
|
|
# Start with a Gemfile that includes `gem <toolgem>`
|
|
|
|
# > nix-shell -p bundler bundix
|
|
|
|
# (shell)> bundle lock
|
|
|
|
# (shell)> bundix
|
|
|
|
# Then use rubyTool in the default.nix:
|
|
|
|
|
2017-06-28 06:33:18 +01:00
|
|
|
# rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; }
|
2017-06-26 01:40:22 +01:00
|
|
|
# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system.
|
2017-05-31 17:44:46 +01:00
|
|
|
{
|
2017-06-28 06:33:18 +01:00
|
|
|
# use the name of the name in question; its version will be picked up from the gemset
|
|
|
|
pname
|
2017-06-09 17:04:33 +01:00
|
|
|
# gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./.
|
2017-05-31 17:44:46 +01:00
|
|
|
, gemdir
|
2017-06-09 17:04:33 +01:00
|
|
|
# Exes is the list of executables provided by the gems in the Gemfile
|
2017-05-31 17:44:46 +01:00
|
|
|
, exes ? []
|
2017-06-11 00:58:32 +01:00
|
|
|
# Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails)
|
2017-05-31 17:44:46 +01:00
|
|
|
, scripts ? []
|
2017-06-11 01:38:49 +01:00
|
|
|
, ruby ? defs.ruby
|
2017-06-09 17:04:33 +01:00
|
|
|
, gemfile ? null
|
|
|
|
, lockfile ? null
|
|
|
|
, gemset ? null
|
2017-06-11 00:58:32 +01:00
|
|
|
, preferLocalBuild ? false
|
|
|
|
, allowSubstitutes ? false
|
2017-06-11 01:11:37 +01:00
|
|
|
, meta ? {}
|
2017-06-11 01:38:49 +01:00
|
|
|
, postBuild ? ""
|
2018-04-09 11:42:50 +01:00
|
|
|
, gemConfig ? null
|
2017-05-31 17:44:46 +01:00
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
2017-06-09 17:04:33 +01:00
|
|
|
basicEnv = (callPackage ../bundled-common {}) args;
|
2017-05-31 17:44:46 +01:00
|
|
|
|
2018-04-09 11:42:50 +01:00
|
|
|
cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" ]
|
2017-05-31 17:44:46 +01:00
|
|
|
// { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults
|
|
|
|
in
|
2017-06-28 06:33:18 +01:00
|
|
|
runCommand basicEnv.name cmdArgs ''
|
2017-06-26 01:40:22 +01:00
|
|
|
mkdir -p $out/bin;
|
|
|
|
${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)}
|
2017-06-11 01:38:49 +01:00
|
|
|
${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " +
|
2017-05-31 17:44:46 +01:00
|
|
|
"--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+
|
|
|
|
"--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+
|
|
|
|
"--set BUNDLE_FROZEN 1 "+
|
|
|
|
"--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+
|
|
|
|
"--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+
|
|
|
|
"--run \"cd $srcdir\";\n") scripts)}
|
|
|
|
${postBuild}
|
|
|
|
''
|