nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib, callPackage, runCommand, makeWrapper, ruby }@defs:
2
3# Use for simple installation of Ruby tools shipped in a Gem.
4# Start with a Gemfile that includes `gem <toolgem>`
5# > nix-shell -p bundler bundix
6# (shell)> bundle lock
7# (shell)> bundix
8# Then use rubyTool in the default.nix:
9
10# rubyTool { pname = "gemifiedTool"; gemdir = ./.; exes = ["gemified-tool"]; }
11# The 'exes' parameter ensures that a copy of e.g. rake doesn't polute the system.
12{
13 # use the name of the name in question; its version will be picked up from the gemset
14 pname
15 # Gemdir is the location of the Gemfile{,.lock} and gemset.nix; usually ./.
16 # This is required unless gemfile, lockfile, and gemset are all provided
17, gemdir ? null
18 # Exes is the list of executables provided by the gems in the Gemfile
19, exes ? []
20 # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails)
21, scripts ? []
22, ruby ? defs.ruby
23, gemfile ? null
24, lockfile ? null
25, gemset ? null
26, preferLocalBuild ? false
27, allowSubstitutes ? false
28, installManpages ? true
29, meta ? {}
30, buildInputs ? []
31, postBuild ? ""
32, gemConfig ? null
33, passthru ? {}
34}@args:
35
36let
37 basicEnv = (callPackage ../bundled-common {}) args;
38
39 cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" "passthru" "gemset" "gemdir" ] // {
40 inherit preferLocalBuild allowSubstitutes; # pass the defaults
41
42 buildInputs = buildInputs ++ lib.optional (scripts != []) makeWrapper;
43
44 meta = { platforms = ruby.meta.platforms; } // meta;
45 passthru = basicEnv.passthru // {
46 inherit basicEnv;
47 inherit (basicEnv) env;
48 } // passthru;
49 };
50in
51 runCommand basicEnv.name cmdArgs ''
52 mkdir -p $out/bin
53 ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)}
54 ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " +
55 "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+
56 "--unset BUNDLE_PATH "+
57 "--set BUNDLE_FROZEN 1 "+
58 "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+
59 "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+
60 "--chdir \"$srcdir\";\n") scripts)}
61
62 ${lib.optionalString installManpages ''
63 for section in {1..9}; do
64 mandir="$out/share/man/man$section"
65 find -L ${basicEnv}/${ruby.gemPath}/gems/${basicEnv.name} \( -wholename "*/man/*.$section" -o -wholename "*/man/man$section/*.$section" \) -print -execdir mkdir -p $mandir \; -execdir cp '{}' $mandir \;
66 done
67 ''}
68 ''