1{ lib, stdenv, callPackage, runCommand, ruby }@defs:
2
3# Use for simple installation of Ruby tools shipped in a Gem.
4# Start with a Gemfile that includes `gem <toolgem>`
5# > nix-shell -p bundler bundix
6# (shell)> bundle lock
7# (shell)> bundix
8# Then use rubyTool in the default.nix:
9
10# rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; }
11# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system.
12{
13 # use the name of the name in question; its version will be picked up from the gemset
14 pname
15 # gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./.
16, gemdir
17 # Exes is the list of executables provided by the gems in the Gemfile
18, exes ? []
19 # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails)
20, scripts ? []
21, ruby ? defs.ruby
22, gemfile ? null
23, lockfile ? null
24, gemset ? null
25, preferLocalBuild ? false
26, allowSubstitutes ? false
27, meta ? {}
28, postBuild ? ""
29}@args:
30
31let
32 basicEnv = (callPackage ../bundled-common {}) args;
33
34 cmdArgs = removeAttrs args [ "pname" "postBuild" ]
35 // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults
36in
37 runCommand basicEnv.name cmdArgs ''
38 mkdir -p $out/bin;
39 ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)}
40 ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " +
41 "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+
42 "--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+
43 "--set BUNDLE_FROZEN 1 "+
44 "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+
45 "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+
46 "--run \"cd $srcdir\";\n") scripts)}
47 ${postBuild}
48 ''