summary refs log tree commit diff
path: root/pkgs/development/tools/pandoc/default.nix
blob: c8c553afad6edf498545c67bf6b48f0c374604c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{ stdenv, lib, haskellPackages, haskell, removeReferencesTo }:

let
  # Since pandoc 3.0 the pandoc binary resides in the pandoc-cli package.
  static = haskell.lib.compose.justStaticExecutables haskellPackages.pandoc-cli;

in
  (haskell.lib.compose.overrideCabal (drv: {
    # pandoc-cli's pandoc executable report the libraries version via --version, match that,
    inherit (static.scope.pandoc) version;
    # but prevent haskellPackages.mkDerivation from recomputing the src tarball based on that.
    inherit (static) src;
    # Make it possible to recover the cli version if necessary.
    passthru = drv.passthru or {} // {
      cliVersion = static.version;
    };

    configureFlags = drv.configureFlags or [] ++ ["-fembed_data_files"];
    buildDepends = drv.buildDepends or [] ++ [haskellPackages.file-embed];
    buildTools = (drv.buildTools or []) ++ [ removeReferencesTo ];

    # Normally, the static linked executable shouldn't refer to any library or the compiler.
    # This is not always the case when the dependency has Paths_* module generated by Cabal,
    # where bindir, datadir, and libdir contain the path to the library, and thus make the
    # executable indirectly refer to GHC. However, most Haskell programs only use Paths_*.version for
    # getting the version at runtime, so it's safe to remove the references to them.
    # This is true so far for pandoc-types and warp.
    # For details see: https://github.com/NixOS/nixpkgs/issues/34376
    postInstall = drv.postInstall or "" + ''
      remove-references-to \
        -t ${haskellPackages.pandoc-types} \
        $out/bin/pandoc
      remove-references-to \
        -t ${haskellPackages.warp} \
        $out/bin/pandoc
      remove-references-to \
        -t ${haskellPackages.pandoc_3_1_8} \
        $out/bin/pandoc
    '' + lib.optionalString (stdenv.buildPlatform == stdenv.hostPlatform) ''
      mkdir -p $out/share/bash-completion/completions
      $out/bin/pandoc --bash-completion > $out/share/bash-completion/completions/pandoc
    '';
  }) static).overrideAttrs (drv: {
    # These libraries are still referenced, because they generate
    # a `Paths_*` module for figuring out their version.
    # The `Paths_*` module is generated by Cabal, and contains the
    # version, but also paths to e.g. the data directories, which
    # lead to a transitive runtime dependency on the whole GHC distribution.
    # This should ideally be fixed in haskellPackages (or even Cabal),
    # but a minimal pandoc is important enough to patch it manually.
    disallowedReferences = [ haskellPackages.pandoc-types haskellPackages.warp haskellPackages.pandoc_3_1_8 ];
  })