From 5f0c43dea417cf3b3d8d4a5c268fc49fc4141296 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Thu, 4 Jul 2019 12:39:29 +0100 Subject: [PATCH 1/5] asciidoctor: move mathematical gem config to default gemset config This has two benefits: - Anyone else using the `mathematical` gem will benefit from the config. - The gem config overrides the default one, so we were losing the fixes for other gems. I had to change how the update script works. Now it looks at the `gems` passthru from `bundlerApp`. --- .../ruby-modules/gem-config/default.nix | 27 +++++++ .../tools/typesetting/asciidoctor/default.nix | 72 ++++++------------- pkgs/tools/typesetting/asciidoctor/update.sh | 4 +- 3 files changed, 49 insertions(+), 54 deletions(-) diff --git a/pkgs/development/ruby-modules/gem-config/default.nix b/pkgs/development/ruby-modules/gem-config/default.nix index 115739bd404..eb136d4c243 100644 --- a/pkgs/development/ruby-modules/gem-config/default.nix +++ b/pkgs/development/ruby-modules/gem-config/default.nix @@ -24,6 +24,7 @@ , msgpack, qt59, libsodium, snappy, libossp_uuid, lxc, libpcap, xorg, gtk2, buildRubyGem , cairo, re2, rake, gobject-introspection, gdk_pixbuf, zeromq, czmq, graphicsmagick, libcxx , file, libvirt, glib, vips, taglib, libopus, linux-pam, libidn, protobuf, fribidi, harfbuzz +, bison, flex, pango, python3, patchelf , libselinux ? null, libsepol ? null }@args: @@ -245,6 +246,32 @@ in ]; }; + mathematical = attrs: { + buildInputs = [ + cmake + bison + flex + glib + pkgconfig + cairo + pango + gdk_pixbuf + libxml2 + python3 + ]; + + # The ruby build script takes care of this + dontUseCmakeConfigure = true; + + # For some reason 'mathematical.so' is missing cairo and glib in its RPATH, add them explicitly here + postFixup = lib.optionalString stdenv.isLinux '' + soPath="$out/${ruby.gemPath}/gems/mathematical-${attrs.version}/lib/mathematical/mathematical.so" + ${patchelf}/bin/patchelf \ + --set-rpath "${lib.makeLibraryPath [ glib cairo ]}:$(${patchelf}/bin/patchelf --print-rpath "$soPath")" \ + "$soPath" + ''; + }; + magic = attrs: { buildInputs = [ file ]; postInstall = '' diff --git a/pkgs/tools/typesetting/asciidoctor/default.nix b/pkgs/tools/typesetting/asciidoctor/default.nix index 0f9bb0ef7de..9da0d291727 100644 --- a/pkgs/tools/typesetting/asciidoctor/default.nix +++ b/pkgs/tools/typesetting/asciidoctor/default.nix @@ -1,59 +1,27 @@ -{ stdenv, lib, bundlerApp, ruby, bundix, mkShell - # Dependencies of the 'mathematical' package -, cmake, bison, flex, glib, pkgconfig, cairo -, pango, gdk_pixbuf, libxml2, python3, patchelf -}: +{ lib, bundlerApp, mkShell, bundix, defaultGemConfig }: -bundlerApp rec { - inherit ruby; - pname = "asciidoctor"; - gemdir = ./.; +let app = bundlerApp { + pname = "asciidoctor"; + gemdir = ./.; - exes = [ - "asciidoctor" - "asciidoctor-pdf" - "asciidoctor-safe" - ]; + exes = [ + "asciidoctor" + "asciidoctor-pdf" + "asciidoctor-safe" + ]; - gemConfig = { - mathematical = attrs: { - buildInputs = [ - cmake - bison - flex - glib - pkgconfig - cairo - pango - gdk_pixbuf - libxml2 - python3 - ]; - - # The ruby build script takes care of this - dontUseCmakeConfigure = true; - - # For some reason 'mathematical.so' is missing cairo and glib in its RPATH, add them explicitly here - postFixup = lib.optionalString stdenv.isLinux '' - soPath="$out/${ruby.gemPath}/gems/mathematical-${attrs.version}/lib/mathematical/mathematical.so" - ${patchelf}/bin/patchelf \ - --set-rpath "${lib.makeLibraryPath [ glib cairo ]}:$(${patchelf}/bin/patchelf --print-rpath "$soPath")" \ - "$soPath" - ''; + meta = with lib; { + description = "A faster Asciidoc processor written in Ruby"; + homepage = https://asciidoctor.org/; + license = licenses.mit; + maintainers = with maintainers; [ gpyh ]; + platforms = platforms.unix; }; }; - passthru.updateShell = mkShell { - buildInputs = (gemConfig.mathematical {}).buildInputs ++ [ - bundix - ]; + shell = mkShell { + buildInputs = + app.gems.mathematical.buildInputs ++ + [ bundix ]; }; - - meta = with lib; { - description = "A faster Asciidoc processor written in Ruby"; - homepage = https://asciidoctor.org/; - license = licenses.mit; - maintainers = with maintainers; [ gpyh ]; - platforms = platforms.unix; - }; -} +in app.overrideAttrs (attrs: { passthru = attrs.passthru // { updateShell = shell; }; }) diff --git a/pkgs/tools/typesetting/asciidoctor/update.sh b/pkgs/tools/typesetting/asciidoctor/update.sh index db7511330be..1f7e5541cee 100755 --- a/pkgs/tools/typesetting/asciidoctor/update.sh +++ b/pkgs/tools/typesetting/asciidoctor/update.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -rm gemset.nix Gemfile.lock nix-shell ../../../.. -A asciidoctor.updateShell --run ' + rm gemset.nix Gemfile.lock bundix -m --bundle-pack-path $TMPDIR/asciidoctor-ruby-bundle + rm -r .bundle ' -rm -r .bundle From 42249205fe851c860d21399dd647352d66819380 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Thu, 4 Jul 2019 12:41:09 +0100 Subject: [PATCH 2/5] asciidctor: include the asciidoctor-epub3 gem This is another common output target for asciidctor that requires an additional gem. The previous commit is necessary for this to work, so that we get the gem config for nokogiri correctly. --- pkgs/tools/typesetting/asciidoctor/Gemfile | 1 + .../typesetting/asciidoctor/Gemfile.lock | 13 +++++ .../tools/typesetting/asciidoctor/default.nix | 2 + pkgs/tools/typesetting/asciidoctor/gemset.nix | 53 +++++++++++++++++++ 4 files changed, 69 insertions(+) diff --git a/pkgs/tools/typesetting/asciidoctor/Gemfile b/pkgs/tools/typesetting/asciidoctor/Gemfile index bdaf1721227..f9329a80a81 100644 --- a/pkgs/tools/typesetting/asciidoctor/Gemfile +++ b/pkgs/tools/typesetting/asciidoctor/Gemfile @@ -2,6 +2,7 @@ source 'https://rubygems.org' gem 'asciidoctor' gem 'asciidoctor-diagram' gem 'asciidoctor-pdf' +gem 'asciidoctor-epub3' gem 'asciidoctor-mathematical' gem 'coderay' gem 'pygments.rb' diff --git a/pkgs/tools/typesetting/asciidoctor/Gemfile.lock b/pkgs/tools/typesetting/asciidoctor/Gemfile.lock index 2195e224bf8..02081e117d6 100644 --- a/pkgs/tools/typesetting/asciidoctor/Gemfile.lock +++ b/pkgs/tools/typesetting/asciidoctor/Gemfile.lock @@ -8,6 +8,11 @@ GEM asciidoctor (2.0.10) asciidoctor-diagram (1.5.18) asciidoctor (>= 1.5.0, < 3.x) + asciidoctor-epub3 (1.5.0.alpha.9) + asciidoctor (>= 1.5.0, < 3.0.0) + concurrent-ruby (~> 1.1.5) + gepub (~> 1.0.2) + thread_safe (~> 0.3.6) asciidoctor-mathematical (0.3.0) asciidoctor (~> 2.0, >= 2.0.0) mathematical (~> 1.5, >= 1.5.8) @@ -27,12 +32,18 @@ GEM concurrent-ruby (1.1.5) css_parser (1.7.0) addressable + gepub (1.0.4) + nokogiri (>= 1.8.2, < 1.11) + rubyzip (>= 1.1.1) hashery (2.1.2) i18n (1.6.0) concurrent-ruby (~> 1.0) mathematical (1.6.12) ruby-enum (~> 0.4) + mini_portile2 (2.4.0) multi_json (1.13.1) + nokogiri (1.10.3) + mini_portile2 (~> 2.4.0) pdf-core (0.7.0) pdf-reader (2.2.0) Ascii85 (~> 1.0.0) @@ -61,6 +72,7 @@ GEM ruby-enum (0.7.2) i18n ruby-rc4 (0.1.5) + rubyzip (1.2.3) safe_yaml (1.0.5) thread_safe (0.3.6) treetop (1.5.3) @@ -73,6 +85,7 @@ PLATFORMS DEPENDENCIES asciidoctor asciidoctor-diagram + asciidoctor-epub3 asciidoctor-mathematical asciidoctor-pdf coderay diff --git a/pkgs/tools/typesetting/asciidoctor/default.nix b/pkgs/tools/typesetting/asciidoctor/default.nix index 9da0d291727..1a34aa78f6d 100644 --- a/pkgs/tools/typesetting/asciidoctor/default.nix +++ b/pkgs/tools/typesetting/asciidoctor/default.nix @@ -8,6 +8,7 @@ let app = bundlerApp { "asciidoctor" "asciidoctor-pdf" "asciidoctor-safe" + "asciidoctor-epub3" ]; meta = with lib; { @@ -22,6 +23,7 @@ let app = bundlerApp { shell = mkShell { buildInputs = app.gems.mathematical.buildInputs ++ + app.gems.nokogiri.buildInputs ++ [ bundix ]; }; in app.overrideAttrs (attrs: { passthru = attrs.passthru // { updateShell = shell; }; }) diff --git a/pkgs/tools/typesetting/asciidoctor/gemset.nix b/pkgs/tools/typesetting/asciidoctor/gemset.nix index 3e416600822..02700962eb2 100644 --- a/pkgs/tools/typesetting/asciidoctor/gemset.nix +++ b/pkgs/tools/typesetting/asciidoctor/gemset.nix @@ -51,6 +51,17 @@ }; version = "1.5.18"; }; + asciidoctor-epub3 = { + dependencies = ["asciidoctor" "concurrent-ruby" "gepub" "thread_safe"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "056yp0z64b1fhhkzz2kaiqsd11gpbgx2d1yjgq7cqma9c70bbxa5"; + type = "gem"; + }; + version = "1.5.0.alpha.9"; + }; asciidoctor-mathematical = { dependencies = ["asciidoctor" "mathematical" "ruby-enum"]; groups = ["default"]; @@ -104,6 +115,17 @@ }; version = "1.7.0"; }; + gepub = { + dependencies = ["nokogiri" "rubyzip"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1kg2h0mscb2hq6l3wjzq5fp5vw4552nglq8n9pawm7bzacf1gzyf"; + type = "gem"; + }; + version = "1.0.4"; + }; hashery = { groups = ["default"]; platforms = []; @@ -136,6 +158,16 @@ }; version = "1.6.12"; }; + mini_portile2 = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "15zplpfw3knqifj9bpf604rb3wc1vhq6363pd6lvhayng8wql5vy"; + type = "gem"; + }; + version = "2.4.0"; + }; multi_json = { groups = ["default"]; platforms = []; @@ -146,6 +178,17 @@ }; version = "1.13.1"; }; + nokogiri = { + dependencies = ["mini_portile2"]; + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "02bjydih0j515szfv9mls195cvpyidh6ixm7dwbl3s2sbaxxk5s4"; + type = "gem"; + }; + version = "1.10.3"; + }; pdf-core = { groups = ["default"]; platforms = []; @@ -284,6 +327,16 @@ }; version = "0.1.5"; }; + rubyzip = { + groups = ["default"]; + platforms = []; + source = { + remotes = ["https://rubygems.org"]; + sha256 = "1w9gw28ly3zyqydnm8phxchf4ymyjl2r7zf7c12z8kla10cpmhlc"; + type = "gem"; + }; + version = "1.2.3"; + }; safe_yaml = { groups = ["default"]; platforms = []; From 855936370c2d44d966c0d1248dff97096cd9be31 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Thu, 4 Jul 2019 13:50:56 +0100 Subject: [PATCH 3/5] asciidoctor: address review comments --- pkgs/tools/typesetting/asciidoctor/default.nix | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkgs/tools/typesetting/asciidoctor/default.nix b/pkgs/tools/typesetting/asciidoctor/default.nix index 1a34aa78f6d..0704600916a 100644 --- a/pkgs/tools/typesetting/asciidoctor/default.nix +++ b/pkgs/tools/typesetting/asciidoctor/default.nix @@ -1,4 +1,4 @@ -{ lib, bundlerApp, mkShell, bundix, defaultGemConfig }: +{ lib, bundlerApp, mkShell, bundix }: let app = bundlerApp { pname = "asciidoctor"; @@ -20,10 +20,9 @@ let app = bundlerApp { }; }; + # Can't be defined directly in the passthru, since app.gems isn't defined at that point. shell = mkShell { - buildInputs = - app.gems.mathematical.buildInputs ++ - app.gems.nokogiri.buildInputs ++ - [ bundix ]; + inputsFrom = lib.mapAttrs app.gems; + buildInputs = [ bundix ]; }; in app.overrideAttrs (attrs: { passthru = attrs.passthru // { updateShell = shell; }; }) From d6b7b2a8cfa0803091a4689fa4d307c538ce6bf9 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Thu, 4 Jul 2019 14:55:02 +0100 Subject: [PATCH 4/5] asciidoctor: wrap asciidoctor-epub3 for epubcheck and kindlegen kindlegen is unfree, so we don't include it by default. The derivation can be overridden to include it. --- pkgs/tools/typesetting/asciidoctor/default.nix | 15 ++++++++++++++- pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkgs/tools/typesetting/asciidoctor/default.nix b/pkgs/tools/typesetting/asciidoctor/default.nix index 0704600916a..16ab64db257 100644 --- a/pkgs/tools/typesetting/asciidoctor/default.nix +++ b/pkgs/tools/typesetting/asciidoctor/default.nix @@ -1,4 +1,9 @@ -{ lib, bundlerApp, mkShell, bundix }: +{ lib, bundlerApp, makeWrapper, + # Optional dependencies, can be null + epubcheck, kindlegen, + # For the update shell + mkShell, bundix +}: let app = bundlerApp { pname = "asciidoctor"; @@ -11,6 +16,14 @@ let app = bundlerApp { "asciidoctor-epub3" ]; + buildInputs = [ makeWrapper ]; + + postBuild = '' + wrapProgram "$out/bin/asciidoctor-epub3" \ + ${lib.optionalString (epubcheck != null) "--set EPUBCHECK ${epubcheck}/bin/epubcheck"} \ + ${lib.optionalString (kindlegen != null) "--set KINDLEGEN ${kindlegen}/bin/kindlegen"} + ''; + meta = with lib; { description = "A faster Asciidoc processor written in Ruby"; homepage = https://asciidoctor.org/; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d2c1c10f5cf..ee30358267b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1922,7 +1922,7 @@ in enableExtraPlugins = true; }); - asciidoctor = callPackage ../tools/typesetting/asciidoctor { }; + asciidoctor = callPackage ../tools/typesetting/asciidoctor { kindlegen = null; }; asunder = callPackage ../applications/audio/asunder { }; From f726160556e74c8203f3f8dff0aa0dec07c0218c Mon Sep 17 00:00:00 2001 From: zimbatm Date: Thu, 4 Jul 2019 18:09:15 +0200 Subject: [PATCH 5/5] asciidoctor: fix update.sh --- .../tools/typesetting/asciidoctor/default.nix | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/pkgs/tools/typesetting/asciidoctor/default.nix b/pkgs/tools/typesetting/asciidoctor/default.nix index 16ab64db257..2f1c7e46154 100644 --- a/pkgs/tools/typesetting/asciidoctor/default.nix +++ b/pkgs/tools/typesetting/asciidoctor/default.nix @@ -1,11 +1,12 @@ -{ lib, bundlerApp, makeWrapper, +{ lib, bundlerApp, makeWrapper, # Optional dependencies, can be null - epubcheck, kindlegen, + epubcheck, kindlegen, # For the update shell - mkShell, bundix + mkShell, bundix }: -let app = bundlerApp { +let + app = bundlerApp { pname = "asciidoctor"; gemdir = ./.; @@ -24,6 +25,10 @@ let app = bundlerApp { ${lib.optionalString (kindlegen != null) "--set KINDLEGEN ${kindlegen}/bin/kindlegen"} ''; + passthru = { + inherit updateShell; + }; + meta = with lib; { description = "A faster Asciidoc processor written in Ruby"; homepage = https://asciidoctor.org/; @@ -33,9 +38,9 @@ let app = bundlerApp { }; }; - # Can't be defined directly in the passthru, since app.gems isn't defined at that point. - shell = mkShell { - inputsFrom = lib.mapAttrs app.gems; - buildInputs = [ bundix ]; + updateShell = mkShell { + inputsFrom = lib.attrValues app.gems; + buildInputs = [ bundix ]; }; -in app.overrideAttrs (attrs: { passthru = attrs.passthru // { updateShell = shell; }; }) +in + app