Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ ruby, lib, callPackage, defaultGemConfig, buildEnv, runCommand 2, buildPackages 3, bundler 4}@defs: 5 6{ name ? null 7, pname ? null 8, gemdir ? null 9, gemfile ? null 10, lockfile ? null 11, gemset ? null 12, groups ? ["default"] 13, ruby ? defs.ruby 14, copyGemFiles ? false # Copy gem files instead of symlinking 15, gemConfig ? defaultGemConfig 16, postBuild ? null 17, document ? [] 18, meta ? {} 19, ignoreCollisions ? false 20, passthru ? {} 21, ... 22}@args: 23 24let 25 inherit (import ../bundled-common/functions.nix { inherit lib ruby gemConfig groups; }) genStubsScript; 26 27 basicEnv = (callPackage ../bundled-common { inherit bundler; }) (args // { inherit pname name; mainGemName = pname; }); 28 29 inherit (basicEnv) envPaths; 30 # Idea here is a mkDerivation that gen-bin-stubs new stubs "as specified" - 31 # either specific executables or the bin/ for certain gem(s), but 32 # incorporates the basicEnv as a requirement so that its $out is in our path. 33 34 # When stubbing the bins for a gem, we should use the gem expression 35 # directly, which means that basicEnv should somehow make it available. 36 37 # Different use cases should use different variations on this file, rather 38 # than the expression trying to deduce a use case. 39 40 # The basicEnv should be put into passthru so that e.g. nix-shell can use it. 41in 42 if pname == null then 43 basicEnv // { inherit name basicEnv; } 44 else 45 let 46 bundlerEnvArgs = { 47 inherit ignoreCollisions; 48 49 name = basicEnv.name; 50 51 paths = envPaths; 52 pathsToLink = [ "/lib" ]; 53 54 postBuild = genStubsScript { 55 inherit lib runCommand ruby bundler groups; 56 confFiles = basicEnv.confFiles; 57 binPaths = [ basicEnv.gems.${pname} ]; 58 } + lib.optionalString (postBuild != null) postBuild; 59 60 meta = { platforms = ruby.meta.platforms; } // meta; 61 passthru = basicEnv.passthru // { 62 inherit basicEnv; 63 inherit (basicEnv) env; 64 } // passthru; 65 }; 66 in 67 if copyGemFiles then 68 runCommand basicEnv.name bundlerEnvArgs '' 69 mkdir -p $out 70 for i in $paths; do 71 ${buildPackages.rsync}/bin/rsync -a $i/lib $out/ 72 done 73 eval "$postBuild" 74 '' 75 else 76 buildEnv bundlerEnvArgs