summary refs log tree commit diff
path: root/pkgs/development/ruby-modules/bundler-app/default.nix
blob: c8f61389ad3fa151db42b261bbbb7d7197cfeab7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{ lib, stdenv, callPackage, runCommand, ruby }@defs:

# 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 ./.
, gemdir
  # 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
, meta ? {}
, postBuild ? ""
, gemConfig ? null
}@args:

let
  basicEnv = (callPackage ../bundled-common {}) args;

  cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" ]
  // { inherit preferLocalBuild allowSubstitutes; }; # pass the defaults
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)}
    ${postBuild}
  ''