1{ ruby, lib, callPackage, defaultGemConfig, buildEnv, runCommand
2, bundler, rsync
3}@defs:
4
5{ name ? null
6, pname ? null
7, gemdir ? null
8, gemfile ? null
9, lockfile ? null
10, gemset ? null
11, groups ? ["default"]
12, ruby ? defs.ruby
13, copyGemFiles ? false # Copy gem files instead of symlinking
14, gemConfig ? defaultGemConfig
15, postBuild ? null
16, document ? []
17, meta ? {}
18, ignoreCollisions ? false
19, passthru ? {}
20, ...
21}@args:
22
23let
24 inherit (import ../bundled-common/functions.nix {inherit lib ruby gemConfig groups; }) genStubsScript;
25
26 basicEnv = (callPackage ../bundled-common { inherit bundler; }) (args // { inherit pname name; mainGemName = pname; });
27
28 inherit (basicEnv) envPaths;
29 # Idea here is a mkDerivation that gen-bin-stubs new stubs "as specified" -
30 # either specific executables or the bin/ for certain gem(s), but
31 # incorporates the basicEnv as a requirement so that its $out is in our path.
32
33 # When stubbing the bins for a gem, we should use the gem expression
34 # directly, which means that basicEnv should somehow make it available.
35
36 # Different use cases should use different variations on this file, rather
37 # than the expression trying to deduce a use case.
38
39 # The basicEnv should be put into passthru so that e.g. nix-shell can use it.
40in
41 if pname == null then
42 basicEnv // { inherit name basicEnv; }
43 else
44 let
45 bundlerEnvArgs = {
46 inherit ignoreCollisions;
47
48 name = basicEnv.name;
49
50 paths = envPaths;
51 pathsToLink = [ "/lib" ];
52
53 postBuild = genStubsScript {
54 inherit lib ruby bundler groups;
55 confFiles = basicEnv.confFiles;
56 binPaths = [ basicEnv.gems.${pname} ];
57 } + lib.optionalString (postBuild != null) postBuild;
58
59 meta = { platforms = ruby.meta.platforms; } // meta;
60 passthru = basicEnv.passthru // {
61 inherit basicEnv;
62 inherit (basicEnv) env;
63 } // passthru;
64 };
65 in
66 if copyGemFiles then
67 runCommand basicEnv.name bundlerEnvArgs ''
68 mkdir -p $out
69 for i in $paths; do
70 ${rsync}/bin/rsync -a $i/lib $out/
71 done
72 eval "$postBuild"
73 ''
74 else
75 buildEnv bundlerEnvArgs