Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at release-19.03 63 lines 2.4 kB view raw
1{ lib, stdenv, 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, gemdir 17 # Exes is the list of executables provided by the gems in the Gemfile 18, exes ? [] 19 # Scripts are ruby programs depend on gems in the Gemfile (e.g. scripts/rails) 20, scripts ? [] 21, ruby ? defs.ruby 22, gemfile ? null 23, lockfile ? null 24, gemset ? null 25, preferLocalBuild ? false 26, allowSubstitutes ? false 27, installManpages ? true 28, meta ? {} 29, buildInputs ? [] 30, postBuild ? "" 31, gemConfig ? null 32, passthru ? {} 33}@args: 34 35let 36 basicEnv = (callPackage ../bundled-common {}) args; 37 38 cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" ] // { 39 inherit preferLocalBuild allowSubstitutes; # pass the defaults 40 41 buildInputs = buildInputs ++ lib.optional (scripts != []) makeWrapper; 42 }; 43in 44 runCommand basicEnv.name cmdArgs '' 45 mkdir -p $out/bin 46 ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)} 47 ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + 48 "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+ 49 "--set BUNDLE_PATH ${basicEnv}/${ruby.gemPath} "+ 50 "--set BUNDLE_FROZEN 1 "+ 51 "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+ 52 "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+ 53 "--run \"cd $srcdir\";\n") scripts)} 54 55 ${lib.optionalString installManpages '' 56 for section in {1..9}; do 57 mandir="$out/share/man/man$section" 58 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 \; 59 done 60 ''} 61 62 ${postBuild} 63 ''