tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
Cleaning out obsolete files
Judson
8 years ago
e4bb4d47
998d011e
-197
2 changed files
expand all
collapse all
unified
split
pkgs
development
ruby-modules
bundler-env
too-complicated.nix
testing
runtests.sh
-195
pkgs/development/ruby-modules/bundler-env/too-complicated.nix
···
1
-
{ stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib
2
-
, callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv
3
-
, git
4
-
, makeWrapper
5
-
, bundler
6
-
, tree
7
-
}@defs:
8
-
9
-
{ name ? null
10
-
, pname ? null
11
-
, gemdir ? null
12
-
, gemfile ? null
13
-
, lockfile ? null
14
-
, gemset ? null
15
-
, allBins ? false
16
-
, ruby ? defs.ruby
17
-
, gemConfig ? defaultGemConfig
18
-
, postBuild ? null
19
-
, document ? []
20
-
, meta ? {}
21
-
, groups ? ["default"]
22
-
, ignoreCollisions ? false
23
-
, ...
24
-
}@args:
25
-
26
-
let
27
-
drvName =
28
-
if name != null then name
29
-
else if pname != null then "${toString pname}-${mainGem.version}"
30
-
else throw "bundlerEnv: either pname or name must be set";
31
-
32
-
mainGem =
33
-
if pname == null then null
34
-
else gems."${pname}" or (throw "bundlerEnv: gem ${pname} not found");
35
-
36
-
gemfile' =
37
-
if gemfile == null then gemdir + "/Gemfile"
38
-
else gemfile;
39
-
40
-
lockfile' =
41
-
if lockfile == null then gemdir + "/Gemfile.lock"
42
-
else lockfile;
43
-
44
-
gemset' =
45
-
if gemset == null then gemdir + "/gemset.nix"
46
-
else gemset;
47
-
48
-
importedGemset = import gemset';
49
-
50
-
platformMatches = attrs: (
51
-
!(attrs ? "platforms") ||
52
-
builtins.any (platform:
53
-
platform.engine == ruby.rubyEngine &&
54
-
(!(platform ? "version") || platform.version == ruby.version.majMin)
55
-
) attrs.platforms
56
-
);
57
-
58
-
groupMatches = attrs: (
59
-
!(attrs ? "groups") ||
60
-
builtins.any (gemGroup: builtins.any (group: group == gemGroup) groups) attrs.groups
61
-
);
62
-
63
-
filteredGemset = lib.filterAttrs (name: attrs: platformMatches attrs && groupMatches attrs) importedGemset;
64
-
65
-
applyGemConfigs = attrs:
66
-
(if gemConfig ? "${attrs.gemName}"
67
-
then attrs // gemConfig."${attrs.gemName}" attrs
68
-
else attrs);
69
-
70
-
configuredGemset = lib.flip lib.mapAttrs filteredGemset (name: attrs:
71
-
applyGemConfigs (attrs // { inherit ruby; gemName = name; })
72
-
);
73
-
74
-
hasBundler = builtins.hasAttr "bundler" filteredGemset;
75
-
76
-
bundler =
77
-
if hasBundler then gems.bundler
78
-
else defs.bundler.override (attrs: { inherit ruby; });
79
-
80
-
pathDerivation = { gemName, version, path, ... }:
81
-
let
82
-
res = {
83
-
type = "derivation";
84
-
bundledByPath = true;
85
-
name = gemName;
86
-
version = version;
87
-
outPath = path;
88
-
outputs = [ "out" ];
89
-
out = res;
90
-
outputName = "out";
91
-
};
92
-
in res;
93
-
94
-
buildGem = name: attrs: (
95
-
let
96
-
gemAttrs = ((removeAttrs attrs ["source"]) // attrs.source // {
97
-
inherit ruby;
98
-
gemName = name;
99
-
gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []);
100
-
});
101
-
in
102
-
if gemAttrs.type == "path" then pathDerivation gemAttrs
103
-
else buildRubyGem gemAttrs);
104
-
105
-
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs);
106
-
107
-
maybeCopyAll = main: if main == null then "" else copyIfBundledByPath main;
108
-
109
-
copyIfBundledByPath = { bundledByPath ? false, ...}@main:
110
-
(if bundledByPath then ''
111
-
cp -a ${gemdir}/* $out/
112
-
'' else ""
113
-
);
114
-
115
-
# We have to normalize the Gemfile.lock, otherwise bundler tries to be
116
-
# helpful by doing so at run time, causing executables to immediately bail
117
-
# out. Yes, I'm serious.
118
-
confFiles = runCommand "gemfile-and-lockfile" {} ''
119
-
mkdir -p $out
120
-
${maybeCopyAll mainGem}
121
-
cp ${gemfile'} $out/Gemfile || ls -l $out/Gemfile
122
-
cp ${lockfile'} $out/Gemfile.lock || ls -l $out/Gemfile.lock
123
-
'';
124
-
125
-
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
126
-
127
-
binPaths = if !allBins && mainGem != null then [ mainGem ] else envPaths;
128
-
129
-
genStubs = binPaths: ''
130
-
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
131
-
"${ruby}/bin/ruby" \
132
-
"${confFiles}/Gemfile" \
133
-
"$out/${ruby.gemPath}" \
134
-
"${bundler}/${ruby.gemPath}" \
135
-
${lib.escapeShellArg binPaths} \
136
-
${lib.escapeShellArg groups}
137
-
'';
138
-
139
-
bundlerEnv = buildEnv {
140
-
inherit ignoreCollisions;
141
-
142
-
name = drvName;
143
-
144
-
paths = envPaths;
145
-
pathsToLink = [ "/lib" ];
146
-
147
-
postBuild = (genStubs binPaths) + lib.optionalString (postBuild != null) postBuild;
148
-
149
-
meta = { platforms = ruby.meta.platforms; } // meta;
150
-
151
-
passthru = rec {
152
-
inherit ruby bundler gems;
153
-
154
-
wrappedRuby = stdenv.mkDerivation {
155
-
name = "wrapped-ruby-${drvName}";
156
-
nativeBuildInputs = [ makeWrapper ];
157
-
buildCommand = ''
158
-
mkdir -p $out/bin
159
-
for i in ${ruby}/bin/*; do
160
-
makeWrapper "$i" $out/bin/$(basename "$i") \
161
-
--set BUNDLE_GEMFILE ${confFiles}/Gemfile \
162
-
--set BUNDLE_PATH ${bundlerEnv}/${ruby.gemPath} \
163
-
--set BUNDLE_FROZEN 1 \
164
-
--set GEM_HOME ${bundlerEnv}/${ruby.gemPath} \
165
-
--set GEM_PATH ${bundlerEnv}/${ruby.gemPath}
166
-
done
167
-
'';
168
-
};
169
-
170
-
env = let
171
-
irbrc = builtins.toFile "irbrc" ''
172
-
if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?)
173
-
require ENV["OLD_IRBRC"]
174
-
end
175
-
require 'rubygems'
176
-
require 'bundler/setup'
177
-
'';
178
-
in stdenv.mkDerivation {
179
-
name = "${drvName}-interactive-environment";
180
-
nativeBuildInputs = [ wrappedRuby bundlerEnv ];
181
-
shellHook = ''
182
-
export OLD_IRBRC="$IRBRC"
183
-
export IRBRC=${irbrc}
184
-
'';
185
-
buildCommand = ''
186
-
echo >&2 ""
187
-
echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***"
188
-
echo >&2 ""
189
-
exit 1
190
-
'';
191
-
};
192
-
};
193
-
};
194
-
in
195
-
bundlerEnv
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-2
pkgs/development/ruby-modules/testing/runtests.sh
···
1
-
#!/usr/bin/env bash
2
-
nix-build -E 'with import <nixpkgs> { }; callPackage ./test.nix {}' --show-trace && cat result
···
0
0