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