git.iko.soy/typeable/pandoc
on 2.0.6 help sign in
typeable/pandoc/default.nix
101 lines 4.3 kB history raw
1# This Nix file can be handy when working on the github version of pandoc.
2#
3# To build pandoc run:
4# nix-build
5# To run a nix shell with everthing needed to build pandoc with cabal:
6# nix-shell
7# To build pandoc for use on Linux and macOS systems without Nix:
8# nix-build -A patched
9{ pkgs ?
10 import ((import <nixpkgs> {}).pkgs.fetchFromGitHub {
11 owner = "NixOS"; repo = "nixpkgs";
12 rev = "1354099daf98b7a1f79e6c41ce6bfda5c40177ae";
13 sha256 = "1dwnmxirzjrshlaan7cpag77y7nd09chrbakfx3c3f1lzsldbi97";
14 }) {} }:
15let haskellPackages = pkgs.haskellPackages;
16 overrides = self: super: {
17 hslua-module-text = pkgs.haskell.lib.dontCheck
18 super.hslua-module-text;
19 skylighting = super.skylighting_0_5;
20 hslua = super.hslua_0_9_3;
21 };
22 source-overrides = {
23 doctemplates = "0.2.1";
24 texmath = "0.10";
25 pandoc-types = pkgs.fetchFromGitHub {
26 owner = "jgm";
27 repo = "pandoc-types";
28 rev = "f1278603a4766f32b8375de84b8581f4bb1e665a";
29 sha256 = "05ykcs8qdjrxly9b6chjr939mv6r42mh51bl58k7jxsr1crxrrf9";
30 };
31 };
32 filterHaskellSource = src:
33 builtins.filterSource (path: type:
34 pkgs.lib.all (i: i != baseNameOf path) [ ".git" "dist-newstyle" "cabal.project.local" "dist" ".stack-work" ".DS_Store" "default.nix" "result" ]
35 && pkgs.lib.all (i: !(pkgs.lib.hasSuffix i path)) [ ".lkshf" ]
36 && pkgs.lib.all (i: !(pkgs.lib.hasPrefix i path)) [ ".ghc.environment." ]
37 ) src;
39 # Normal nix derivation
40 drv = (
41 haskellPackages.extend (
42 pkgs.lib.composeExtensions (
43 haskellPackages.packageSourceOverrides source-overrides
44 ) overrides
45 )
46 ).callCabal2nix "pandoc" (filterHaskellSource ./.) {};
48 # Like drv but with static linking for haskell libraries
49 static = pkgs.haskell.lib.justStaticExecutables (drv.overrideAttrs (old: {
50 buildInputs = old.buildInputs ++ [
51 pkgs.zlib.static
52 haskellPackages.file-embed
53 ];
54 configureFlags = [
55 "-fembed_data_files"
56 "--disable-executable-dynamic"
57 ];
58 }));
60 # Patch binaries for use on macOS and linux systems without nix
61 # and bundle the required gmp and lua libraries
62 patched = pkgs.stdenv.mkDerivation {
63 name = "pandoc-patched";
64 buildInputs = [
65 static
66 pkgs.zip
67 pkgs.gnutar
68 ];
69 unpackPhase = "true";
70 buildPhase = "true";
71 installPhase = if pkgs.stdenv.isDarwin
72 then ''
73 mkdir -p $out/bin
74 cp ${static}/bin/pandoc $out/bin
75 cp ${pkgs.gmp}/lib/libgmp.10.dylib $out/bin
76 cp ${pkgs.lua5_3}/lib/liblua.5.3.4.dylib $out/bin
77 chmod +w $out/bin/*
78 echo patching libgmp and liblua
79 install_name_tool -id "@executable_path/libgmp.10.dylib" "$out/bin/libgmp.10.dylib"
80 install_name_tool -id "@executable_path/liblua.5.3.4.dylib" "$out/bin/liblua.5.3.4.dylib"
81 for fn in $out/bin/*; do
82 echo patching $fn
83 install_name_tool -change "${pkgs.libiconv}/lib/libiconv.dylib" /usr/lib/libiconv.dylib "$fn"
84 install_name_tool -change "${pkgs.stdenv.libc}/lib/libSystem.B.dylib" /usr/lib/libSystem.B.dylib "$fn"
85 install_name_tool -change "${pkgs.gmp}/lib/libgmp.10.dylib" "@executable_path/libgmp.10.dylib" "$fn"
86 install_name_tool -change "${pkgs.lua5_3}/lib/liblua.5.3.4.dylib" "@executable_path/liblua.5.3.4.dylib" "$fn"
87 done
88 (cd $out/.. && zip -r $out/pandoc-macOS.zip `basename $out`/bin)
89 ''
90 else ''
91 mkdir -p $out/bin
92 cp ${static}/bin/pandoc $out/bin
93 cp ${pkgs.gmp}/lib/libgmp.so* $out/bin
94 cp ${pkgs.lua5_3}/lib/liblua.so* $out/bin
95 chmod +w $out/bin/pandoc
96 patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $out/bin/pandoc
97 patchelf --set-rpath '$ORIGIN' $out/bin/pandoc
98 (cd $out/.. && tar -czf $out/pandoc-linux.tar.gz `basename $out`/bin)
99 '';
100 };
101in if pkgs.lib.inNixShell then drv.env else drv // { inherit static patched; }