2021-02-05 17:12:51 +00:00
|
|
|
{ lib, callPackage, runCommand, makeWrapper, ruby }@defs:
|
2020-04-24 23:36:52 +00: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:
|
|
|
|
|
|
|
|
# rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; }
|
|
|
|
# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system.
|
|
|
|
{
|
|
|
|
# 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 ./.
|
|
|
|
# This is required unless gemfile, lockfile, and gemset are all provided
|
|
|
|
, gemdir ? null
|
|
|
|
# Exes is the list of executables provided by the gems in the Gemfile
|
|
|
|
, exes ? []
|
|
|
|
# Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails)
|
|
|
|
, scripts ? []
|
|
|
|
, ruby ? defs.ruby
|
|
|
|
, gemfile ? null
|
|
|
|
, lockfile ? null
|
|
|
|
, gemset ? null
|
|
|
|
, preferLocalBuild ? false
|
|
|
|
, allowSubstitutes ? false
|
|
|
|
, installManpages ? true
|
|
|
|
, meta ? {}
|
2022-08-12 12:06:08 +00:00
|
|
|
, nativeBuildInputs ? []
|
2020-04-24 23:36:52 +00:00
|
|
|
, buildInputs ? []
|
|
|
|
, postBuild ? ""
|
|
|
|
, gemConfig ? null
|
|
|
|
, passthru ? {}
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
2022-10-30 15:09:59 +00:00
|
|
|
basicEnv = (callPackage ../bundled-common {
|
|
|
|
inherit ruby;
|
|
|
|
}) args;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" "passthru" "gemset" "gemdir" ] // {
|
|
|
|
inherit preferLocalBuild allowSubstitutes; # pass the defaults
|
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
nativeBuildInputs = nativeBuildInputs ++ lib.optionals (scripts != []) [ makeWrapper ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
meta = {
|
|
|
|
mainProgram = pname;
|
|
|
|
inherit (ruby.meta) platforms;
|
|
|
|
} // meta;
|
2020-04-24 23:36:52 +00:00
|
|
|
passthru = basicEnv.passthru // {
|
|
|
|
inherit basicEnv;
|
|
|
|
inherit (basicEnv) env;
|
|
|
|
} // passthru;
|
|
|
|
};
|
|
|
|
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 "+
|
|
|
|
"--unset BUNDLE_PATH "+
|
|
|
|
"--set BUNDLE_FROZEN 1 "+
|
|
|
|
"--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+
|
|
|
|
"--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+
|
2022-04-27 09:35:20 +00:00
|
|
|
"--chdir \"$srcdir\";\n") scripts)}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
${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
|
|
|
|
''}
|
|
|
|
''
|