summaryrefslogtreecommitdiff
path: root/pkgs/development/ruby-modules/bundler-env/default.nix
blob: a103dcd6ae7aaabd0259e6b3ae15336e283a0cf5 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
  ruby,
  lib,
  callPackage,
  defaultGemConfig,
  buildEnv,
  runCommand,
  buildPackages,
  bundler,
}@defs:

{
  name ? null,
  pname ? null,
  gemdir ? null,
  gemfile ? null,
  lockfile ? null,
  gemset ? null,
  groups ? [ "default" ],
  ruby ? defs.ruby,
  copyGemFiles ? false, # Copy gem files instead of symlinking
  gemConfig ? defaultGemConfig,
  postBuild ? null,
  document ? [ ],
  meta ? { },
  ignoreCollisions ? false,
  passthru ? { },
  ...
}@args:

let
  inherit
    (import ../bundled-common/functions.nix {
      inherit
        lib
        ruby
        gemConfig
        groups
        ;
    })
    genStubsScript
    ;

  basicEnv = (callPackage ../bundled-common { inherit bundler; }) (
    args
    // {
      inherit pname name;
      mainGemName = pname;
    }
  );

  inherit (basicEnv) envPaths;
  # Idea here is a mkDerivation that gen-bin-stubs new stubs "as specified" -
  # either specific executables or the bin/ for certain gem(s), but
  # incorporates the basicEnv as a requirement so that its $out is in our path.

  # When stubbing the bins for a gem, we should use the gem expression
  # directly, which means that basicEnv should somehow make it available.

  # Different use cases should use different variations on this file, rather
  # than the expression trying to deduce a use case.

in
# The basicEnv should be put into passthru so that e.g. nix-shell can use it.
if pname == null then
  basicEnv // { inherit name basicEnv; }
else
  let
    bundlerEnvArgs = {
      inherit ignoreCollisions;

      inherit (basicEnv) pname version;

      paths = envPaths;
      pathsToLink = [ "/lib" ];

      postBuild =
        genStubsScript {
          inherit
            lib
            runCommand
            ruby
            bundler
            groups
            ;
          confFiles = basicEnv.confFiles;
          binPaths = [ basicEnv.gems.${pname} ];
        }
        + lib.optionalString (postBuild != null) postBuild;

      meta = {
        platforms = ruby.meta.platforms;
      }
      // meta;
      passthru =
        basicEnv.passthru
        // {
          inherit basicEnv;
          inherit (basicEnv) env;
        }
        // passthru;
    };
  in
  if copyGemFiles then
    runCommand basicEnv.name bundlerEnvArgs ''
      mkdir -p $out
      for i in $paths; do
        ${buildPackages.rsync}/bin/rsync -a $i/lib $out/
      done
      eval "$postBuild"
    ''
  else
    buildEnv bundlerEnvArgs