git.iko.soy/typeable/pandoc
on 2.6 help sign in
typeable/pandoc/default.nix
96 lines 4.1 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 everything 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 = "42b9b8f7c8687cb26e69c3559e0e1346fb0e680f";
13 sha256 = "01zcd0dh9x3qf5yflclbrcvff9yh8k9pmccc7vjlq3phc440qsyb";
14 }) {} }:
15let haskellPackages = pkgs.haskellPackages;
16 overrides = self: super: { };
17 source-overrides = {
18 doctemplates = "0.2.1";
19 texmath = "0.10";
20 pandoc-types = pkgs.fetchFromGitHub {
21 owner = "jgm";
22 repo = "pandoc-types";
23 rev = "f1278603a4766f32b8375de84b8581f4bb1e665a";
24 sha256 = "05ykcs8qdjrxly9b6chjr939mv6r42mh51bl58k7jxsr1crxrrf9";
25 };
26 };
27 filterHaskellSource = src:
28 builtins.filterSource (path: type:
29 pkgs.lib.all (i: i != baseNameOf path) [ ".git" "dist-newstyle" "cabal.project.local" "dist" ".stack-work" ".DS_Store" "default.nix" "result" ]
30 && pkgs.lib.all (i: !(pkgs.lib.hasSuffix i path)) [ ".lkshf" ]
31 && pkgs.lib.all (i: !(pkgs.lib.hasPrefix i path)) [ ".ghc.environment." ]
32 ) src;
34 # Normal nix derivation
35 drv = (
36 haskellPackages.extend (
37 pkgs.lib.composeExtensions (
38 haskellPackages.packageSourceOverrides source-overrides
39 ) overrides
40 )
41 ).callCabal2nix "pandoc" (filterHaskellSource ./.) {};
43 # Like drv but with static linking for haskell libraries
44 static = pkgs.haskell.lib.justStaticExecutables (drv.overrideAttrs (old: {
45 buildInputs = old.buildInputs ++ [
46 pkgs.zlib.static
47 haskellPackages.file-embed
48 ];
49 configureFlags = [
50 "-fembed_data_files"
51 "--disable-executable-dynamic"
52 ];
53 }));
55 # Patch binaries for use on macOS and linux systems without nix
56 # and bundle the required gmp and lua libraries
57 patched = pkgs.stdenv.mkDerivation {
58 name = "pandoc-patched";
59 buildInputs = [
60 static
61 pkgs.zip
62 pkgs.gnutar
63 ];
64 unpackPhase = "true";
65 buildPhase = "true";
66 installPhase = if pkgs.stdenv.isDarwin
67 then ''
68 mkdir -p $out/bin
69 cp ${static}/bin/pandoc $out/bin
70 cp ${pkgs.gmp}/lib/libgmp.10.dylib $out/bin
71 cp ${pkgs.lua5_3}/lib/liblua.5.3.4.dylib $out/bin
72 chmod +w $out/bin/*
73 echo patching libgmp and liblua
74 install_name_tool -id "@executable_path/libgmp.10.dylib" "$out/bin/libgmp.10.dylib"
75 install_name_tool -id "@executable_path/liblua.5.3.4.dylib" "$out/bin/liblua.5.3.4.dylib"
76 for fn in $out/bin/*; do
77 echo patching $fn
78 install_name_tool -change "${pkgs.libiconv}/lib/libiconv.dylib" /usr/lib/libiconv.dylib "$fn"
79 install_name_tool -change "${pkgs.stdenv.libc}/lib/libSystem.B.dylib" /usr/lib/libSystem.B.dylib "$fn"
80 install_name_tool -change "${pkgs.gmp}/lib/libgmp.10.dylib" "@executable_path/libgmp.10.dylib" "$fn"
81 install_name_tool -change "${pkgs.lua5_3}/lib/liblua.5.3.4.dylib" "@executable_path/liblua.5.3.4.dylib" "$fn"
82 done
83 (cd $out/.. && zip -r $out/pandoc-macOS.zip `basename $out`/bin)
84 ''
85 else ''
86 mkdir -p $out/bin
87 cp ${static}/bin/pandoc $out/bin
88 cp ${pkgs.gmp}/lib/libgmp.so* $out/bin
89 cp ${pkgs.lua5_3}/lib/liblua.so* $out/bin
90 chmod +w $out/bin/pandoc
91 patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $out/bin/pandoc
92 patchelf --set-rpath '$ORIGIN' $out/bin/pandoc
93 (cd $out/.. && tar -czf $out/pandoc-linux.tar.gz `basename $out`/bin)
94 '';
95 };
96in if pkgs.lib.inNixShell then drv.env else drv // { inherit static patched; }