blob: 5be820b60e300162fe84ce9b03c15ff6df20e545 (
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
|
{ stdenv, lib, buildEnv, buildRubyGem, ruby, gemConfig, makeWrapper }:
/*
Example usage:
nix-shell -E "(import <nixpkgs> {}).ruby.withPackages (pkgs: with pkgs; [ pry nokogiri ])"
You can also use this for writing ruby scripts that run anywhere that has nix
using a nix-shell shebang:
#!/usr/bin/env nix-shell
#!nix-shell -i ruby -p "ruby.withPackages (pkgs: with pkgs; [ pry nokogiri ])"
Run the following in the nixpkgs root directory to update the ruby-packages.nix:
./maintainers/scripts/update-ruby-packages
*/
let
functions = import ../bundled-common/functions.nix { inherit lib gemConfig; };
buildGems = gemset:
let
realGemset = if builtins.isAttrs gemset then gemset else import gemset;
builtGems =
lib.mapAttrs (name: initialAttrs:
let
attrs = functions.applyGemConfigs ({ inherit ruby; gemName = name; } // initialAttrs);
in
buildRubyGem (functions.composeGemAttrs ruby builtGems name attrs)
) realGemset;
in builtGems;
gems = buildGems (import ../../../top-level/ruby-packages.nix);
withPackages = selector:
let
selected = selector gems;
gemEnv = buildEnv {
name = "ruby-gems";
paths = selected;
pathsToLink = [ "/lib" "/bin" "/nix-support" ];
};
wrappedRuby = stdenv.mkDerivation {
name = "wrapped-${ruby.name}";
nativeBuildInputs = [ makeWrapper ];
buildCommand = ''
mkdir -p $out/bin
for i in ${ruby}/bin/*; do
makeWrapper "$i" $out/bin/$(basename "$i") --set GEM_PATH ${gemEnv}/${ruby.gemPath}
done
'';
};
in stdenv.mkDerivation {
name = "${ruby.name}-with-packages";
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ selected ruby ];
dontUnpack = true;
installPhase = ''
for i in ${ruby}/bin/* ${gemEnv}/bin/*; do
rm -f $out/bin/$(basename "$i")
makeWrapper "$i" $out/bin/$(basename "$i") --set GEM_PATH ${gemEnv}/${ruby.gemPath}
done
ln -s ${ruby}/nix-support $out/nix-support
'';
passthru = {
inherit wrappedRuby;
gems = selected;
};
};
in { inherit withPackages gems buildGems; }
|