summary refs log tree commit diff
path: root/pkgs/development/ruby-modules/bundler-env/default.nix
blob: d1fa4785c06ca9cd656faabd41d235cb01f6cc71 (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
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
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
, linkFarm
, git
, makeWrapper
, bundler
, tree
}@defs:

{ name ? null
, pname ? null
, gemdir ? null
, gemfile ? null
, lockfile ? null
, gemset ? null
, ruby ? defs.ruby
, gemConfig ? defaultGemConfig
, postBuild ? null
, document ? []
, meta ? {}
, groups ? ["default"]
, ignoreCollisions ? false
, ...
}@args:

let
  inherit (import ./functions.nix (defs // args)) genStubsScript;

  drvName =
    if name != null then name
    else if pname != null then "${toString pname}-${basicEnv.gems."${pname}".version}"
    else throw "bundlerEnv: either pname or name must be set";

  gemfile' =
    if gemfile == null then gemdir + "/Gemfile"
    else gemfile;

  lockfile' =
    if lockfile == null then gemdir + "/Gemfile.lock"
    else lockfile;

  gemset' =
    if gemset == null then gemdir + "/gemset.nix"
    else gemset;

  basicEnv = (callPackage ./basic.nix {}) (args // { inherit pname gemdir;
    gemfile = gemfile';
    lockfile  = lockfile';
    gemset = gemset';
  });

  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.

  # The basicEnv should be put into passthru so that e.g. nix-shell can use it.
in
  if builtins.trace "pname: ${toString pname}" pname == null then
    basicEnv // { inherit name; }
  else
    (buildEnv {
      inherit ignoreCollisions;

      name = builtins.trace "name: ${toString drvName}" drvName;

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

      postBuild = genStubsScript defs // args // {
        inherit bundler;
        confFiles = basicEnv.confFiles;
        binPaths = [ basicEnv.mainGem ];
      } + lib.optionalString (postBuild != null) postBuild;

      meta = { platforms = ruby.meta.platforms; } // meta;
      passthru = basicEnv.passthru // {
        inherit basicEnv;
        inherit (basicEnv) env;
      };
    })