nixpkgs/pkgs/development/ruby-modules/bundler-app/default.nix

64 lines
2.3 KiB
Nix
Raw Normal View History

{ lib, stdenv, callPackage, runCommand, makeWrapper, ruby }@defs:
2017-06-26 02:40:22 +02: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 07:33:18 +02:00
# rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; }
2017-06-26 02:40:22 +02:00
# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system.
{
2017-06-28 07:33:18 +02:00
# use the name of the name in question; its version will be picked up from the gemset
pname
# gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./.
, gemdir
# Exes is the list of executables provided by the gems in the Gemfile
, exes ? []
2017-06-11 01:58:32 +02:00
# Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails)
, scripts ? []
, ruby ? defs.ruby
, gemfile ? null
, lockfile ? null
, gemset ? null
2017-06-11 01:58:32 +02:00
, preferLocalBuild ? false
, allowSubstitutes ? false
, installManpages ? true
2017-06-11 02:11:37 +02:00
, meta ? {}
, buildInputs ? []
, postBuild ? ""
, gemConfig ? null
2018-11-28 12:21:37 +01:00
, passthru ? {}
}@args:
let
basicEnv = (callPackage ../bundled-common {}) args;
cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" ] // {
inherit preferLocalBuild allowSubstitutes; # pass the defaults
buildInputs = buildInputs ++ lib.optional (scripts != []) makeWrapper;
};
in
runCommand basicEnv.name cmdArgs ''
mkdir -p $out/bin
${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)}
${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " +
"--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)}
${lib.optionalString installManpages ''
for section in {1..9}; do
mandir="$out/share/man/man$section"
find -L ${basicEnv}/${ruby.gemPath}/gems/${basicEnv.name} \( -wholename "*/man/*.$section" -o -wholename "*/man/man$section/*.$section" \) -print -execdir mkdir -p $mandir \; -execdir cp '{}' $mandir \;
done
''}
${postBuild}
''