Something went wrong. Try again.
What happens if I push all of nixpkgs
Something went wrong. Try again.
5.8 kB · 256 lines
Nix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257{ stdenv, lib, buildPackages, runCommand, ruby, defaultGemConfig, buildRubyGem, buildEnv, makeBinaryWrapper, bundler,}@defs:
{ name ? null, pname ? null, version ? null, mainGemName ? null, gemdir ? null, gemfile ? null, lockfile ? null, gemset ? null, ruby ? defs.ruby, copyGemFiles ? false, # Copy gem files instead of symlinking gemConfig ? defaultGemConfig, postBuild ? null, document ? [ ], meta ? { }, groups ? null, ignoreCollisions ? false, nativeBuildInputs ? [ ], buildInputs ? [ ], extraConfigPaths ? [ ], passthru ? { }, ...}@args:
assert name == null -> pname != null;
let functions = import ./functions.nix { inherit lib gemConfig; };
inherit (functions) applyGemConfigs bundlerFiles composeGemAttrs filterGemset genStubsScript pathDerivation ;
gemFiles = bundlerFiles args;
importedGemset = if builtins.typeOf gemFiles.gemset != "set" then import gemFiles.gemset else gemFiles.gemset;
filteredGemset = filterGemset { inherit ruby groups; } importedGemset;
configuredGemset = lib.flip lib.mapAttrs filteredGemset ( name: attrs: applyGemConfigs ( attrs // { inherit ruby document; gemName = name; } ) );
hasBundler = builtins.hasAttr "bundler" filteredGemset;
bundler = if hasBundler then gems.bundler else defs.bundler.override (attrs: { inherit ruby; });
gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildGem name attrs);
version' = if version != null then version else if pname != null then gems.${pname}.suffix else null;
name' = if name != null then name else "${pname}-${version'}";
pname' = if pname != null then pname else name;
copyIfBundledByPath = { bundledByPath ? false, ... }: (lib.optionalString bundledByPath ( assert gemFiles.gemdir != null; "cp -a ${gemFiles.gemdir}/* $out/" ) # */ );
maybeCopyAll = pkgname: lib.optionalString (pkgname != null) ( let mainGem = gems.${pkgname} or (throw "bundlerEnv: gem ${pkgname} not found"); in copyIfBundledByPath mainGem );
# We have to normalize the Gemfile.lock, otherwise bundler tries to be # helpful by doing so at run time, causing executables to immediately bail # out. Yes, I'm serious. confFiles = runCommand "gemfile-and-lockfile" { } '' mkdir -p $out ${maybeCopyAll mainGemName} cp ${gemFiles.gemfile} $out/Gemfile || ls -l $out/Gemfile cp ${gemFiles.lockfile} $out/Gemfile.lock || ls -l $out/Gemfile.lock
${lib.concatMapStringsSep "\n" (path: "cp -r ${path} $out/") extraConfigPaths} '';
buildGem = name: attrs: ( let gemAttrs = composeGemAttrs ruby gems name attrs; in if gemAttrs.type == "path" then pathDerivation (gemAttrs.source // gemAttrs) else buildRubyGem gemAttrs );
envPaths = lib.attrValues gems ++ lib.optional (!hasBundler) bundler;
basicEnvArgs = { inherit nativeBuildInputs buildInputs ignoreCollisions pname ;
name = name'; version = version';
paths = envPaths; pathsToLink = [ "/lib" ];
postBuild = genStubsScript ( defs // args // { inherit confFiles bundler groups; binPaths = envPaths; } ) + lib.optionalString (postBuild != null) postBuild;
meta = { platforms = ruby.meta.platforms; } // meta;
passthru = ( lib.optionalAttrs (pname != null) { inherit (gems.${pname}) gemType; } // rec { inherit ruby bundler gems confFiles envPaths ;
wrappedRuby = stdenv.mkDerivation { name = "wrapped-ruby-${pname'}";
nativeBuildInputs = [ makeBinaryWrapper ];
dontUnpack = true;
buildPhase = '' mkdir -p $out/bin for i in ${ruby}/bin/*; do makeWrapper "$i" $out/bin/$(basename "$i") \ --set BUNDLE_GEMFILE ${confFiles}/Gemfile \ --unset BUNDLE_PATH \ --set BUNDLE_FROZEN 1 \ --set GEM_HOME ${basicEnv}/${ruby.gemPath} \ --set GEM_PATH ${basicEnv}/${ruby.gemPath} done '';
dontInstall = true;
doCheck = true; checkPhase = '' $out/bin/ruby --help > /dev/null '';
inherit (ruby) meta; };
env = let irbrc = builtins.toFile "irbrc" '' if !(ENV["OLD_IRBRC"].nil? || ENV["OLD_IRBRC"].empty?) require ENV["OLD_IRBRC"] end require 'rubygems' require 'bundler/setup' ''; in stdenv.mkDerivation { name = "${pname'}-interactive-environment"; nativeBuildInputs = [ wrappedRuby basicEnv ]; shellHook = '' export OLD_IRBRC=$IRBRC export IRBRC=${irbrc} ''; buildCommand = '' echo >&2 "" echo >&2 "*** Ruby 'env' attributes are intended for interactive nix-shell sessions, not for building! ***" echo >&2 "" exit 1 ''; }; } // passthru ); };
basicEnv = if copyGemFiles then runCommand name' basicEnvArgs '' mkdir -p $out for i in $paths; do ${buildPackages.rsync}/bin/rsync -a $i/lib $out/ done eval "$postBuild" '' else buildEnv basicEnvArgs;inbasicEnv