Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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, nativeBuildInputs ? [] 31, buildInputs ? [] 32, postBuild ? "" 33, gemConfig ? null 34, passthru ? {} 35}@args: 36 37let 38 basicEnv = (callPackage ../bundled-common { 39 inherit ruby; 40 }) args; 41 42 cmdArgs = removeAttrs args [ "pname" "postBuild" "gemConfig" "passthru" "gemset" "gemdir" ] // { 43 inherit preferLocalBuild allowSubstitutes; # pass the defaults 44 45 nativeBuildInputs = nativeBuildInputs ++ lib.optionals (scripts != []) [ makeWrapper ]; 46 47 meta = { 48 mainProgram = pname; 49 inherit (ruby.meta) platforms; 50 } // meta; 51 passthru = basicEnv.passthru // { 52 inherit basicEnv; 53 inherit (basicEnv) env; 54 } // passthru; 55 }; 56in 57 runCommand basicEnv.name cmdArgs '' 58 mkdir -p $out/bin 59 ${(lib.concatMapStrings (x: "ln -s '${basicEnv}/bin/${x}' $out/bin/${x};\n") exes)} 60 ${(lib.concatMapStrings (s: "makeWrapper $out/bin/$(basename ${s}) $srcdir/${s} " + 61 "--set BUNDLE_GEMFILE ${basicEnv.confFiles}/Gemfile "+ 62 "--unset BUNDLE_PATH "+ 63 "--set BUNDLE_FROZEN 1 "+ 64 "--set GEM_HOME ${basicEnv}/${ruby.gemPath} "+ 65 "--set GEM_PATH ${basicEnv}/${ruby.gemPath} "+ 66 "--chdir \"$srcdir\";\n") scripts)} 67 68 ${lib.optionalString installManpages '' 69 for section in {1..9}; do 70 mandir="$out/share/man/man$section" 71 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 \; 72 done 73 ''} 74 ''