nixpkgs/pkgs/by-name/pa/pandoc/package.nix
aleksana 571c71e6f7 treewide: migrate packages to pkgs/by-name, take 1
We are migrating packages that meet below requirements:

1. using `callPackage`
2. called path is a directory
3. overriding set is empty (`{ }`)
4. not containing path expressions other than relative path (to
makenixpkgs-vet happy)
5. not referenced by nix files outside of the directory, other
than`pkgs/top-level/all-packages.nix`
6. not referencing nix files outside of the directory
7. not referencing `default.nix` (since it's changed to `package.nix`)
8. `outPath` doesn't change after migration

The tool is here: https://github.com/Aleksanaa/by-name-migrate.
2024-11-09 20:04:51 +08:00

49 lines
2.3 KiB
Nix

{ stdenv, lib, haskellPackages, haskell, removeReferencesTo, installShellFiles }:
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: {
configureFlags = drv.configureFlags or [] ++ ["-fembed_data_files"];
buildDepends = drv.buildDepends or [] ++ [haskellPackages.file-embed];
buildTools = (drv.buildTools or []) ++ [
removeReferencesTo
installShellFiles
];
# 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} \
$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
'' + ''
installManPage man/*
'';
}) 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 ];
})