From 86f1579266db4e65571f83acb1400f9943d1d1fb Mon Sep 17 00:00:00 2001 From: zimbatm Date: Wed, 2 Mar 2016 10:05:01 +0000 Subject: [PATCH 1/4] ruby: install rubygems directly into the derivation Having a separate rubygems package can lead to split-brain scenarios. Since rubygems is designed to replace himself on a ruby installation, let's do that. --- .../ruby/build-ruby-gem/default.nix | 9 ++-- .../interpreters/ruby/bundler-env/default.nix | 7 +-- .../development/interpreters/ruby/default.nix | 43 ++++++++++++++----- .../interpreters/ruby/gem_hook.patch | 6 +-- .../interpreters/ruby/rubygems-src.nix | 8 ++++ .../interpreters/ruby/rubygems.nix | 35 --------------- pkgs/top-level/all-packages.nix | 3 +- 7 files changed, 48 insertions(+), 63 deletions(-) create mode 100644 pkgs/development/interpreters/ruby/rubygems-src.nix delete mode 100644 pkgs/development/interpreters/ruby/rubygems.nix diff --git a/pkgs/development/interpreters/ruby/build-ruby-gem/default.nix b/pkgs/development/interpreters/ruby/build-ruby-gem/default.nix index db1ef4c6c439..6e1b0c00bd08 100644 --- a/pkgs/development/interpreters/ruby/build-ruby-gem/default.nix +++ b/pkgs/development/interpreters/ruby/build-ruby-gem/default.nix @@ -18,7 +18,7 @@ # Normal gem packages can be used outside of bundler; a binstub is created in # $out/bin. -{ lib, ruby, rubygems, bundler, fetchurl, fetchgit, makeWrapper, git, +{ lib, ruby, bundler, fetchurl, fetchgit, makeWrapper, git, buildRubyGem, darwin } @ defs: @@ -54,9 +54,6 @@ lib.makeOverridable ( let shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'"; - rubygems = (attrs.rubygems or defs.rubygems).override { - inherit ruby; - }; src = attrs.src or ( if type == "gem" then fetchurl { @@ -79,14 +76,14 @@ let in stdenv.mkDerivation (attrs // { - inherit ruby rubygems; + inherit ruby; inherit doCheck; inherit dontBuild; inherit dontStrip; inherit type; buildInputs = [ - ruby rubygems makeWrapper + ruby makeWrapper ] ++ lib.optionals (type == "git") [ git bundler ] ++ lib.optional stdenv.isDarwin darwin.libobjc ++ buildInputs; diff --git a/pkgs/development/interpreters/ruby/bundler-env/default.nix b/pkgs/development/interpreters/ruby/bundler-env/default.nix index 0c9ed40d3f82..d5e2154ab3b3 100644 --- a/pkgs/development/interpreters/ruby/bundler-env/default.nix +++ b/pkgs/development/interpreters/ruby/bundler-env/default.nix @@ -1,6 +1,5 @@ { stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib , callPackage, defaultGemConfig, fetchurl, fetchgit, buildRubyGem, buildEnv -, rubygems , git , makeWrapper , bundler @@ -28,10 +27,9 @@ let ); hasBundler = builtins.hasAttr "bundler" importedGemset; bundler = if hasBundler then gems.bundler else defs.bundler.override (attrs: { inherit ruby; }); - rubygems = defs.rubygems.override (attrs: { inherit ruby; }); gems = lib.flip lib.mapAttrs configuredGemset (name: attrs: buildRubyGem ((removeAttrs attrs ["source"]) // attrs.source // { - inherit ruby rubygems; + inherit ruby; gemName = name; gemPath = map (gemName: gems."${gemName}") (attrs.dependencies or []); })); @@ -45,7 +43,6 @@ let cd $out chmod +w Gemfile.lock - source ${rubygems}/nix-support/setup-hook export GEM_PATH=${bundler}/${ruby.gemPath} ${ruby}/bin/ruby -rubygems -e \ "require 'bundler'; Bundler.definition.lock('Gemfile.lock')" @@ -56,8 +53,6 @@ let paths = envPaths; pathsToLink = [ "/lib" ]; postBuild = '' - source ${rubygems}/nix-support/setup-hook - ${ruby}/bin/ruby ${./gen-bin-stubs.rb} \ "${ruby}/bin/ruby" \ "${confFiles}/Gemfile" \ diff --git a/pkgs/development/interpreters/ruby/default.nix b/pkgs/development/interpreters/ruby/default.nix index 2a22cc74e754..2085d558df5f 100644 --- a/pkgs/development/interpreters/ruby/default.nix +++ b/pkgs/development/interpreters/ruby/default.nix @@ -9,6 +9,10 @@ let opString = stdenv.lib.optionalString; patchSet = import ./rvm-patchsets.nix { inherit fetchFromGitHub; }; config = import ./config.nix { inherit fetchFromSavannah; }; + rubygemsSrc = import ./rubygems-src.nix { inherit fetchurl; }; + unpackdir = obj: + lib.removeSuffix ".tgz" + (lib.removeSuffix ".tar.gz" obj.name); generic = { majorVersion, minorVersion, teenyVersion, patchLevel, sha256 }: let versionNoPatch = "${majorVersion}.${minorVersion}.${teenyVersion}"; @@ -32,12 +36,8 @@ let , autoreconfHook, bison, autoconf , darwin ? null }: - stdenv.mkDerivation rec { - inherit version; - - name = "ruby-${version}"; - - src = if useRailsExpress then fetchFromGitHub { + let rubySrc = + if useRailsExpress then fetchFromGitHub { owner = "ruby"; repo = "ruby"; rev = tag; @@ -46,6 +46,18 @@ let url = "http://cache.ruby-lang.org/pub/ruby/${majorVersion}.${minorVersion}/ruby-${fullVersionName}.tar.gz"; sha256 = sha256.src; }; + in + stdenv.mkDerivation rec { + inherit version; + + name = "ruby-${version}"; + + srcs = [ rubySrc rubygemsSrc ]; + sourceRoot = + if useRailsExpress then + "ruby-${tag}-src" + else + unpackdir rubySrc; # Have `configure' avoid `/usr/bin/nroff' in non-chroot builds. NROFF = "${groff}/bin/nroff"; @@ -67,11 +79,15 @@ let enableParallelBuilding = true; - patches = (import ./patchsets.nix { - inherit patchSet useRailsExpress ops patchLevel; - })."${versionNoPatch}"; + patches = + [ ./gem_hook.patch ] ++ + (import ./patchsets.nix { + inherit patchSet useRailsExpress ops patchLevel; + })."${versionNoPatch}"; - postUnpack = opString isRuby21 '' + postUnpack = '' + cp -r ${unpackdir rubygemsSrc} ${sourceRoot}/rubygems + '' + opString isRuby21 '' rm "$sourceRoot/enc/unicode/name2ctype.h" ''; @@ -99,6 +115,11 @@ let installFlags = stdenv.lib.optionalString docSupport "install-doc"; # Bundler tries to create this directory postInstall = '' + # Update rubygems + pushd rubygems + $out/bin/ruby setup.rb + popd + # Bundler tries to create this directory mkdir -pv $out/${passthru.gemPath} mkdir -p $out/nix-support @@ -119,7 +140,7 @@ let meta = { license = stdenv.lib.licenses.ruby; - homepage = "http://www.ruby-lang.org/en/"; + homepage = http://www.ruby-lang.org/en/; description = "The Ruby language"; platforms = stdenv.lib.platforms.all; }; diff --git a/pkgs/development/interpreters/ruby/gem_hook.patch b/pkgs/development/interpreters/ruby/gem_hook.patch index 07f942f505e5..e75794fa5566 100644 --- a/pkgs/development/interpreters/ruby/gem_hook.patch +++ b/pkgs/development/interpreters/ruby/gem_hook.patch @@ -1,7 +1,7 @@ -diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb +diff --git a/rubygems/lib/rubygems/installer.rb b/rubygems/lib/rubygems/installer.rb index d1ef3cb..bf15652 100755 ---- a/lib/rubygems/installer.rb -+++ b/lib/rubygems/installer.rb +--- a/rubygems/lib/rubygems/installer.rb ++++ b/rubygems/lib/rubygems/installer.rb @@ -545,6 +545,13 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')} say path if Gem.configuration.really_verbose diff --git a/pkgs/development/interpreters/ruby/rubygems-src.nix b/pkgs/development/interpreters/ruby/rubygems-src.nix new file mode 100644 index 000000000000..191da98e56ed --- /dev/null +++ b/pkgs/development/interpreters/ruby/rubygems-src.nix @@ -0,0 +1,8 @@ +{ fetchurl +, version ? "2.4.8" +, sha256 ? "0pl4civyf0vhqsqbqaivvxrb3fsg8sid9a8jv5vfnk4hypz3ahss" +}: +fetchurl { + url = "http://production.cf.rubygems.org/rubygems/rubygems-${version}.tgz"; + sha256 = sha256; +} diff --git a/pkgs/development/interpreters/ruby/rubygems.nix b/pkgs/development/interpreters/ruby/rubygems.nix deleted file mode 100644 index fb210ceff4bf..000000000000 --- a/pkgs/development/interpreters/ruby/rubygems.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ stdenv, lib, fetchurl, makeWrapper, ruby }: - -stdenv.mkDerivation rec { - name = "rubygems-${version}"; - version = "2.4.8"; - src = fetchurl { - url = "http://production.cf.rubygems.org/rubygems/${name}.tgz"; - sha256 = "0pl4civyf0vhqsqbqaivvxrb3fsg8sid9a8jv5vfnk4hypz3ahss"; - }; - - patches = [ ./gem_hook.patch ]; - - buildInputs = [ruby makeWrapper]; - - buildPhase = ":"; - - installPhase = '' - ruby setup.rb --prefix=$out/ - - wrapProgram $out/bin/gem --prefix RUBYLIB : $out/lib - - find $out -type f -name "*.rb" | - xargs sed -i "s@/usr/bin/env@$(type -p env)@g" - - mkdir -pv $out/nix-support - cat > $out/nix-support/setup-hook < Date: Wed, 2 Mar 2016 10:12:23 +0000 Subject: [PATCH 2/4] bundler: 1.10.6 -> 1.11.2 --- pkgs/development/interpreters/ruby/bundler.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/ruby/bundler.nix b/pkgs/development/interpreters/ruby/bundler.nix index cdcd12990e27..718da20b0068 100644 --- a/pkgs/development/interpreters/ruby/bundler.nix +++ b/pkgs/development/interpreters/ruby/bundler.nix @@ -4,7 +4,7 @@ buildRubyGem rec { inherit ruby; name = "${gemName}-${version}"; gemName = "bundler"; - version = "1.10.6"; - sha256 = "1vlzfq0bkkj4jyq6av0y55mh5nj5n0f3mfbmmifwgkh44g8k6agv"; + version = "1.11.2"; + sha256 = "0s37j1hyngc4shq0in8f9y1knjdqkisdg3dd1mfwgq7n1bz8zan7"; dontPatchShebangs = true; } From 19820e9a9633e68b72e27f173d7b367a99577655 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 1 Mar 2016 20:00:54 +0000 Subject: [PATCH 3/4] ruby: add a new .dev output to ruby derivations The idea is to bundle ruby, bundler and bundix together. I was having issues where bundler was installed with ruby 2.3.0 and I wanted to use ruby 2.0.0. With this change all the developer has to do is install `ruby_2_0_0.dev` either in his environment or in a nix-shell. --- .../development/interpreters/ruby/default.nix | 8 ++++++- pkgs/development/interpreters/ruby/dev.nix | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 pkgs/development/interpreters/ruby/dev.nix diff --git a/pkgs/development/interpreters/ruby/default.nix b/pkgs/development/interpreters/ruby/default.nix index 2085d558df5f..2ff960f6fcc6 100644 --- a/pkgs/development/interpreters/ruby/default.nix +++ b/pkgs/development/interpreters/ruby/default.nix @@ -1,6 +1,7 @@ { stdenv, lib, fetchurl, fetchFromSavannah, fetchFromGitHub , zlib, openssl, gdbm, ncurses, readline, groff, libyaml, libffi, autoreconfHook, bison , autoconf, darwin ? null +, buildEnv, bundler, bundix } @ args: let @@ -35,6 +36,7 @@ let , libffi, fiddleSupport ? true , autoreconfHook, bison, autoconf , darwin ? null + , buildEnv, bundler, bundix }: let rubySrc = if useRailsExpress then fetchFromGitHub { @@ -146,11 +148,15 @@ let }; passthru = rec { - inherit majorVersion minorVersion teenyVersion patchLevel; + inherit majorVersion minorVersion teenyVersion patchLevel version; rubyEngine = "ruby"; baseRuby = baseruby; libPath = "lib/${rubyEngine}/${versionNoPatch}"; gemPath = "lib/${rubyEngine}/gems/${versionNoPatch}"; + dev = import ./dev.nix { + inherit buildEnv bundler bundix; + ruby = self; + }; }; } ) args; in self; diff --git a/pkgs/development/interpreters/ruby/dev.nix b/pkgs/development/interpreters/ruby/dev.nix new file mode 100644 index 000000000000..7787306eb324 --- /dev/null +++ b/pkgs/development/interpreters/ruby/dev.nix @@ -0,0 +1,24 @@ +/* An environment for development that bundles ruby, bundler and bundix + together. This avoids version conflicts where each is using a diferent + version of each-other. +*/ +{ buildEnv, ruby, bundler, bundix }: +let + bundler_ = bundler.override { + ruby = ruby; + }; + bundix_ = bundix.override { + ruby = ruby; + bundler = bundler_; + }; +in +buildEnv { + name = "${ruby.rubyEngine}-dev-${ruby.version}"; + paths = [ + bundix_ + bundler_ + ruby + ]; + pathsToLink = [ "/bin" ]; + ignoreCollisions = true; +} From d9cf99225b7205ce521daab968d4b16e5e91a5c2 Mon Sep 17 00:00:00 2001 From: zimbatm Date: Mon, 14 Mar 2016 23:28:55 +0000 Subject: [PATCH 4/4] rubygems: 2.4.8 -> 2.6.2 --- .../interpreters/ruby/gem_hook.patch | 23 +++++++++++-------- .../interpreters/ruby/rubygems-src.nix | 4 ++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/pkgs/development/interpreters/ruby/gem_hook.patch b/pkgs/development/interpreters/ruby/gem_hook.patch index e75794fa5566..78ff9ddbb1a9 100644 --- a/pkgs/development/interpreters/ruby/gem_hook.patch +++ b/pkgs/development/interpreters/ruby/gem_hook.patch @@ -1,18 +1,21 @@ diff --git a/rubygems/lib/rubygems/installer.rb b/rubygems/lib/rubygems/installer.rb -index d1ef3cb..bf15652 100755 +index a88d393..8612901 100644 --- a/rubygems/lib/rubygems/installer.rb +++ b/rubygems/lib/rubygems/installer.rb -@@ -545,6 +545,13 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')} +@@ -766,7 +766,15 @@ TEXT + # Ensures that files can't be installed outside the gem directory. - say path if Gem.configuration.really_verbose - end -+ -+ if !ENV['NIX_POST_EXTRACT_FILES_HOOK'].nil? -+ print "\nrunning NIX_POST_EXTRACT_FILES_HOOK #{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{@gem_dir}\n" -+ print `#{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{@gem_dir}` -+ print "\nrunning NIX_POST_EXTRACT_FILES_HOOK done\n" + def extract_files +- @package.extract_files gem_dir ++ ret = @package.extract_files gem_dir ++ if ENV['NIX_POST_EXTRACT_FILES_HOOK'] ++ puts ++ puts "running NIX_POST_EXTRACT_FILES_HOOK #{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{gem_dir}" ++ system("#{ENV['NIX_POST_EXTRACT_FILES_HOOK']} #{gem_dir}") ++ puts "running NIX_POST_EXTRACT_FILES_HOOK done" ++ puts + end -+ ++ ret end ## diff --git a/pkgs/development/interpreters/ruby/rubygems-src.nix b/pkgs/development/interpreters/ruby/rubygems-src.nix index 191da98e56ed..fea749e7de0e 100644 --- a/pkgs/development/interpreters/ruby/rubygems-src.nix +++ b/pkgs/development/interpreters/ruby/rubygems-src.nix @@ -1,6 +1,6 @@ { fetchurl -, version ? "2.4.8" -, sha256 ? "0pl4civyf0vhqsqbqaivvxrb3fsg8sid9a8jv5vfnk4hypz3ahss" +, version ? "2.6.2" +, sha256 ? "1j02ajici555f35vd6ky6m4bxs8lh8nqb1c59qqib4jp4ibcv6zy" }: fetchurl { url = "http://production.cf.rubygems.org/rubygems/rubygems-${version}.tgz";