From f52c32fcfccbecfc52f68571a3ce866f59e91459 Mon Sep 17 00:00:00 2001 From: Charles Strahan Date: Wed, 21 Jan 2015 15:20:42 -0500 Subject: [PATCH] ruby: rewrite `sup` package --- .../networking/mailreaders/sup/Gemfile | 10 +- .../networking/mailreaders/sup/Gemfile.lock | 24 +++- .../networking/mailreaders/sup/default.nix | 119 +++++++----------- .../networking/mailreaders/sup/gemset.nix | 96 +++++++++++++- .../mailreaders/sup/mkrf_conf_xapian.rb | 14 +++ .../mailreaders/sup/xapian-Rakefile | 38 ++++++ .../interpreters/ruby/bundler-env.nix | 30 +++-- .../interpreters/ruby/monkey_patches.rb | 11 +- pkgs/development/libraries/xapian/default.nix | 6 +- pkgs/top-level/all-packages.nix | 32 +---- 10 files changed, 248 insertions(+), 132 deletions(-) create mode 100644 pkgs/applications/networking/mailreaders/sup/mkrf_conf_xapian.rb create mode 100644 pkgs/applications/networking/mailreaders/sup/xapian-Rakefile diff --git a/pkgs/applications/networking/mailreaders/sup/Gemfile b/pkgs/applications/networking/mailreaders/sup/Gemfile index f7d13a163268..a57feb5d21f3 100644 --- a/pkgs/applications/networking/mailreaders/sup/Gemfile +++ b/pkgs/applications/networking/mailreaders/sup/Gemfile @@ -1,6 +1,8 @@ source "https://rubygems.org" -#gem "sup", "0.20.0" -#gem 'sup', '~> 0.20.0' -#gem 'gpgme' -gem 'gpgme', '2.0.7' +gem 'sup' +gem 'gpgme' + +# Sup tries to `xapian-ruby` in its extconf instead of listing it as a +# dependency. +gem 'xapian-ruby', "~> 1.2.15" diff --git a/pkgs/applications/networking/mailreaders/sup/Gemfile.lock b/pkgs/applications/networking/mailreaders/sup/Gemfile.lock index 2f56752d9a2f..fe8746b9f724 100644 --- a/pkgs/applications/networking/mailreaders/sup/Gemfile.lock +++ b/pkgs/applications/networking/mailreaders/sup/Gemfile.lock @@ -1,12 +1,34 @@ GEM remote: https://rubygems.org/ specs: + chronic (0.9.1) gpgme (2.0.7) mini_portile (>= 0.5.0, <= 0.6.0) + highline (1.6.21) + locale (2.1.0) + lockfile (2.1.3) + mime-types (1.25.1) mini_portile (0.6.0) + ncursesw (1.4.9) + rmail-sup (1.0.1) + sup (0.20.0) + chronic (~> 0.9.1) + highline + locale (~> 2.0) + lockfile + mime-types (~> 1.0) + ncursesw (~> 1.4.0) + rmail-sup (~> 1.0.1) + trollop (>= 1.12) + unicode (~> 0.4.4) + trollop (2.1.1) + unicode (0.4.4.2) + xapian-ruby (1.2.19.1) PLATFORMS ruby DEPENDENCIES - gpgme (= 2.0.7) + gpgme + sup + xapian-ruby (~> 1.2.15) diff --git a/pkgs/applications/networking/mailreaders/sup/default.nix b/pkgs/applications/networking/mailreaders/sup/default.nix index 3d537d83f430..874d662754f9 100644 --- a/pkgs/applications/networking/mailreaders/sup/default.nix +++ b/pkgs/applications/networking/mailreaders/sup/default.nix @@ -1,79 +1,52 @@ -{ stdenv, fetchurl, ruby, rake, rubygems, makeWrapper, ncursesw_sup -, xapian_ruby, gpgme, libiconvOrEmpty, mime_types, chronic, trollop, lockfile -, gettext, iconv, locale, text, highline, rmail_sup, unicode, gnupg, which -, bundler, git }: +{ stdenv, lib, bundlerEnv, gpgme, ruby, ncurses, writeText, zlib, xapian, pkgconfig, which }: -stdenv.mkDerivation rec { - version = "0.18.0"; - name = "sup-${version}"; +bundlerEnv { + name = "sup-0.20.0"; - meta = { + inherit ruby; + gemfile = ./Gemfile; + lockfile = ./Gemfile.lock; + gemset = ./gemset.nix; + + fixes.gpgme = attrs: { + buildInputs = [ gpgme ]; + }; + + fixes.ncursesw = attrs: { + buildInputs = [ ncurses ]; + buildArgs = [ + "--with-cflags=-I${ncurses}/include" + "--with-ldflags=-L${ncurses}/lib" + ]; + }; + + fixes.xapian-ruby = attrs: { + # use the system xapian + buildInputs = [ xapian pkgconfig zlib ]; + postPatch = '' + cp ${./xapian-Rakefile} Rakefile + ''; + preInstall = '' + export XAPIAN_CONFIG=${xapian}/bin/xapian-config + ''; + }; + + fixes.sup = attrs: { + # prevent sup from trying to dynamically install `xapian-ruby`. + postPatch = '' + cp ${./mkrf_conf_xapian.rb} ext/mkrf_conf_xapian.rb + + substituteInPlace lib/sup/crypto.rb \ + --replace 'which gpg2' \ + '${which}/bin/which gpg2' + ''; + }; + + meta = with lib; { description = "A curses threads-with-tags style email client"; homepage = http://supmua.org; - license = stdenv.lib.licenses.gpl2; - maintainers = with stdenv.lib.maintainers; [ lovek323 ]; - platforms = stdenv.lib.platforms.unix; - broken = true; + license = with licenses; gpl2; + maintainers = with maintainers; [ cstrahan lovek323 ]; + platforms = platforms.unix; }; - - dontStrip = true; - - src = fetchurl { - url = "https://github.com/sup-heliotrope/sup/archive/release-${version}.tar.gz"; - sha256 = "1dhg0i2v0ddhwi32ih5lc56x00kbaikd2wdplgzlshq0nljr9xy0"; - }; - - buildInputs = - [ rake ruby rubygems makeWrapper gpgme ncursesw_sup xapian_ruby - libiconvOrEmpty git ]; - - phases = [ "unpackPhase" "buildPhase" "installPhase" ]; - - buildPhase = '' - # the builder uses git to get a listing of the files - export EMAIL="nobody@in.here" - git init >/dev/null - git add . - git commit -m "message" >/dev/null - gem build sup.gemspec - ''; - - installPhase = '' - export HOME=$TMP/home; mkdir -pv "$HOME" - - GEM_PATH="$GEM_PATH:$out/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${chronic}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${gettext}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${gpgme}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${highline}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${iconv}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${locale}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${lockfile}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${mime_types}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${ncursesw_sup}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${rmail_sup}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${text}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${trollop}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${unicode}/${ruby.gemPath}" - GEM_PATH="$GEM_PATH:${xapian_ruby}/${ruby.gemPath}" - - # Don't install some dependencies -- we have already installed - # the dependencies but gem doesn't acknowledge this - gem install --no-verbose --install-dir "$out/${ruby.gemPath}" \ - --bindir "$out/bin" --no-rdoc --no-ri sup-${version}.gem \ - --ignore-dependencies >/dev/null - - # specify ruby interpreter explicitly - sed -i '1 s|^.*$|#!${ruby}/bin/ruby|' bin/sup-sync-back-maildir - - cp bin/sup-sync-back-maildir "$out/bin" - - for prog in $out/bin/*; do - wrapProgram "$prog" --prefix GEM_PATH : "$GEM_PATH" --prefix PATH : "${gnupg}/bin:${which}/bin" - done - - for prog in $out/gems/*/bin/*; do - [[ -e "$out/bin/$(basename $prog)" ]] - done - ''; } diff --git a/pkgs/applications/networking/mailreaders/sup/gemset.nix b/pkgs/applications/networking/mailreaders/sup/gemset.nix index de28a5dfeb39..e39da3dac85e 100644 --- a/pkgs/applications/networking/mailreaders/sup/gemset.nix +++ b/pkgs/applications/networking/mailreaders/sup/gemset.nix @@ -1,7 +1,14 @@ { - gpgme = { + "chronic" = { + version = "0.9.1"; + source = { + type = "gem"; + sha256 = "0kspaxpfy7yvyk1lvpx31w852qfj8wb9z04mcj5bzi70ljb9awqk"; + }; + }; + "gpgme" = { version = "2.0.7"; - src = { + source = { type = "gem"; sha256 = "1p84zhiri2ihcld7py9mwc2kg5xs5da8fk11zhndrhmw05yvf5mr"; }; @@ -9,11 +16,92 @@ "mini_portile" ]; }; - mini_portile = { + "highline" = { + version = "1.6.21"; + source = { + type = "gem"; + sha256 = "06bml1fjsnrhd956wqq5k3w8cyd09rv1vixdpa3zzkl6xs72jdn1"; + }; + }; + "locale" = { + version = "2.1.0"; + source = { + type = "gem"; + sha256 = "18bb0g24flq9dr8qv4j7pm7w9i2vmvmqrbmry95ibf1r1c4s60yj"; + }; + }; + "lockfile" = { + version = "2.1.3"; + source = { + type = "gem"; + sha256 = "0dij3ijywylvfgrpi2i0k17f6w0wjhnjjw0k9030f54z56cz7jrr"; + }; + }; + "mime-types" = { + version = "1.25.1"; + source = { + type = "gem"; + sha256 = "0mhzsanmnzdshaba7gmsjwnv168r1yj8y0flzw88frw1cickrvw8"; + }; + }; + "mini_portile" = { version = "0.6.0"; - src = { + source = { type = "gem"; sha256 = "09kcn4g63xrdirgwxgjikqg976rr723bkc9bxfr29pk22cj3wavn"; }; }; + "ncursesw" = { + version = "1.4.9"; + source = { + type = "gem"; + sha256 = "154cls3b237imdbhih7rni5p85nw6mpbpkzdw08jxzvqaml7q093"; + }; + }; + "rmail-sup" = { + version = "1.0.1"; + source = { + type = "gem"; + sha256 = "1xswk101s560lxqaax3plqh8vjx7jjspnggdwb3q80m358f92q9g"; + }; + }; + "sup" = { + version = "0.20.0"; + source = { + type = "gem"; + sha256 = "1lpqgrqkv29xr1h1142qsbmknlshpgys7fc3w1nkyhib8s3ikamg"; + }; + dependencies = [ + "chronic" + "highline" + "locale" + "lockfile" + "mime-types" + "ncursesw" + "rmail-sup" + "trollop" + "unicode" + ]; + }; + "trollop" = { + version = "2.1.1"; + source = { + type = "gem"; + sha256 = "0z5dvh7glwqjprlihsjx67hfzy4whsjfhqj9akyyrby9q5va1i4k"; + }; + }; + "unicode" = { + version = "0.4.4.2"; + source = { + type = "gem"; + sha256 = "15fggljzan8zvmr8h12b5m7pcj1gvskmmnx367xs4p0rrpnpil8g"; + }; + }; + "xapian-ruby" = { + version = "1.2.19.1"; + source = { + type = "gem"; + sha256 = "1crfrmc8kf6qq1xcfcmgf213zg66badpg4d86n7y9x3i1f5lxlbv"; + }; + }; } \ No newline at end of file diff --git a/pkgs/applications/networking/mailreaders/sup/mkrf_conf_xapian.rb b/pkgs/applications/networking/mailreaders/sup/mkrf_conf_xapian.rb new file mode 100644 index 000000000000..e19f06e23ac2 --- /dev/null +++ b/pkgs/applications/networking/mailreaders/sup/mkrf_conf_xapian.rb @@ -0,0 +1,14 @@ +require 'rubygems' +require 'rubygems/command.rb' +require 'rubygems/dependency_installer.rb' +require 'rbconfig' + +begin + Gem::Command.build_args = ARGV +rescue NoMethodError +end + +# create dummy rakefile to indicate success +f = File.open(File.join(File.dirname(__FILE__), "Rakefile"), "w") +f.write("task :default\n") +f.close diff --git a/pkgs/applications/networking/mailreaders/sup/xapian-Rakefile b/pkgs/applications/networking/mailreaders/sup/xapian-Rakefile new file mode 100644 index 000000000000..9f0b8e72f08c --- /dev/null +++ b/pkgs/applications/networking/mailreaders/sup/xapian-Rakefile @@ -0,0 +1,38 @@ +# encoding: utf-8 +# Install the xapian binaries into the lib folder of the gem +require 'rbconfig' + +c = RbConfig::CONFIG + +def system!(cmd) + puts cmd + system(cmd) or raise +end + +source_dir = 'xapian_source' +bindings = Dir["#{source_dir}/xapian-bindings-*"].first +bindings = File.basename(bindings, ".tar.xz") + +task :default do + system! "tar -xJf #{source_dir}/#{bindings}.tar.xz" + + prefix = Dir.pwd + ENV['LDFLAGS'] = "-L#{prefix}/lib" + + system! "mkdir -p lib" + + Dir.chdir bindings do + ENV['RUBY'] ||= "#{c['bindir']}/#{c['RUBY_INSTALL_NAME']}" + system! "./configure --prefix=#{prefix} --exec-prefix=#{prefix} --with-ruby" + system! "make clean all" + end + + system! "cp -r #{bindings}/ruby/.libs/_xapian.* lib" + system! "cp #{bindings}/ruby/xapian.rb lib" + + system! "rm lib/*.la" + system! "rm lib/*.lai" + + system! "rm -R #{bindings}" + system! "rm -R #{source_dir}" +end diff --git a/pkgs/development/interpreters/ruby/bundler-env.nix b/pkgs/development/interpreters/ruby/bundler-env.nix index 1ea982c111e4..3ccc1b8ff917 100644 --- a/pkgs/development/interpreters/ruby/bundler-env.nix +++ b/pkgs/development/interpreters/ruby/bundler-env.nix @@ -1,6 +1,5 @@ { stdenv, runCommand, writeText, writeScript, writeScriptBin, ruby, lib , callPackage , gemFixes, fetchurl, fetchgit, buildRubyGem -#, bundler_PATCHED , bundler_HEAD , git }@defs: @@ -10,7 +9,9 @@ { name, gemset, gemfile, lockfile, ruby ? defs.ruby, fixes ? gemFixes , enableParallelBuilding ? false # TODO: this might not work, given the env-var shinanigans. -, documentation ? false}@args: +, documentation ? false +, meta ? {} +}@args: let @@ -127,22 +128,26 @@ let needsPreInstall = attrs: (attrs ? preInstall) || (attrs ? buildInputs) || (attrs ? nativeBuildInputs); - createPreInstallers = lib.fold (next: acc: + # TODO: support cross compilation? look at stdenv/generic/default.nix. + runPreInstallers = lib.fold (next: acc: if !needsPreInstall next then acc else acc + '' - cp ${writeScript "${next.name}-pre-install" '' + ${writeScript "${next.name}-pre-install" '' #!${stdenv.shell} - buildInputs="${toString (next.buildInputs or [])}" - nativeBuildInputs="${toString (next.nativeBuildInputs or [])}" + export nativeBuildInputs="${toString ((next.nativeBuildInputs or []) ++ (next.buildInputs or []))}" source ${stdenv}/setup + header "running pre-install script for ${next.name}" + ${next.preInstall or ""} ${ruby}/bin/ruby -e 'print ENV.inspect' > env/${next.name} - ''} pre-installers/${next.name} + + stopNest + ''} '' ) "" (attrValues instantiated); @@ -245,18 +250,23 @@ in stdenv.mkDerivation { inherit name; + buildInputs = [ ruby bundler git ]; + phases = [ "installPhase" "fixupPhase" ]; + outputs = [ "out" # the installed libs/bins "bundle" # supporting files for bundler ]; + installPhase = '' # Copy the Gemfile and Gemfile.lock + mkdir -p $bundle export BUNDLE_GEMFILE=$bundle/Gemfile cp ${gemfile} $BUNDLE_GEMFILE @@ -273,8 +283,7 @@ stdenv.mkDerivation { ${copyGems} mkdir env - mkdir pre-installers - ${createPreInstallers} + ${runPreInstallers} ${allBuildArgs} @@ -289,8 +298,11 @@ stdenv.mkDerivation { export RUBYOPT="-rmonkey_patches.rb -I $(pwd -P)" bundler install --frozen --binstubs ${lib.optionalString enableParallelBuilding "--jobs $NIX_BUILD_CORES"} ''; + passthru = { inherit ruby; inherit bundler; }; + + inherit meta; } diff --git a/pkgs/development/interpreters/ruby/monkey_patches.rb b/pkgs/development/interpreters/ruby/monkey_patches.rb index 8e5ab632f74b..5877f2e7bfb2 100644 --- a/pkgs/development/interpreters/ruby/monkey_patches.rb +++ b/pkgs/development/interpreters/ruby/monkey_patches.rb @@ -133,14 +133,9 @@ Bundler::Installer.class_eval do # and then set it back to what it was originally. alias original_install_gem_from_spec install_gem_from_spec def install_gem_from_spec(spec, standalone = false, worker = 0) - pre_installer = "pre-installers/#{spec.name}" - if File.exist?(pre_installer) - system(pre_installer) - unless $?.success? - Bundler.ui.error "The pre-installer script for #{spec.name} failed!" - exit 1 - end - env = eval(Bundler.read_file("env/#{spec.name}")) + env_dump = "env/#{spec.name}" + if File.exist?(env_dump) + env = eval(Bundler.read_file(env_dump)) unless env Bundler.ui.error "The environment variables for #{spec.name} could not be loaded!" exit 1 diff --git a/pkgs/development/libraries/xapian/default.nix b/pkgs/development/libraries/xapian/default.nix index d74a85a9162d..575fb73084c5 100644 --- a/pkgs/development/libraries/xapian/default.nix +++ b/pkgs/development/libraries/xapian/default.nix @@ -1,11 +1,11 @@ { stdenv, fetchurl, libuuid, zlib }: stdenv.mkDerivation { - name = "xapian-1.2.8"; + name = "xapian-1.2.19"; src = fetchurl { - url = http://oligarchy.co.uk/xapian/1.2.8/xapian-core-1.2.8.tar.gz; - sha256 = "00411ebac66a5592b87fc57ccfeb234c84b929ed23c185befb5df9929df3d4f9"; + url = http://oligarchy.co.uk/xapian/1.2.19/xapian-core-1.2.19.tar.xz; + sha256 = "11a7lm3w3pchk4rx144nc2p31994spyqmldm18ph86zzi01jcy2a"; }; buildInputs = [ libuuid zlib ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 72eaa4075173..177fd3d657e6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -10643,42 +10643,14 @@ let pcmanfm = callPackage ../applications/misc/pcmanfm { }; - ruby_gpgme = callPackage ../development/libraries/ruby_gpgme { - ruby = ruby_1_9_3; - hoe = rubyPackages.hoe; - }; - - ruby_ncursesw_sup = callPackage ../development/libraries/ruby_ncursesw_sup { }; - shotcut = callPackage ../applications/video/shotcut { mlt = mlt-qt5; }; smplayer = callPackage ../applications/video/smplayer { }; smtube = callPackage ../applications/video/smtube {}; - sup = with rubyPackages; callPackage ../applications/networking/mailreaders/sup { - ruby = ruby_1_9_3.override { - cursesSupport = true; - }; - - inherit gettext highline iconv locale lockfile - text trollop xapian_ruby which; - - rmail_sup = ""; # missing - unicode = ""; - - # See https://github.com/NixOS/nixpkgs/issues/1804 and - # https://github.com/NixOS/nixpkgs/issues/2146 - bundler = pkgs.lib.overrideDerivation pkgs.rubyPackages.bundler ( - oldAttrs: { - dontPatchShebangs = 1; - } - ); - chronic = chronic; - gpgme = ruby_gpgme; - mime_types = mime_types; - ncursesw_sup = ruby_ncursesw_sup; - rake = rake; + sup = callPackage ../applications/networking/mailreaders/sup { + ruby = ruby_1_9_3.override { cursesSupport = true; }; }; synfigstudio = callPackage ../applications/graphics/synfigstudio {