Merge pull request #10 from basvandijk/removeReferencesToSrcFromDocs

Remove references to the source code from the generated cargo docs
This commit is contained in:
Nicolas Mattia 2019-08-23 16:29:37 +02:00 committed by GitHub
commit f4773e30aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,6 +9,22 @@ src:
, copyBuildArtifacts ? false
, doCheck ? true
, doDoc ? true
#| Whether to remove references to source code from the generated cargo docs
# to reduce Nix closure size. By default cargo doc includes snippets like the
# following in the generated highlighted source code in files like: src/rand/lib.rs.html:
#
# <meta name="description" content="Source to the Rust file `/nix/store/mdwpqciww926xayfasl85i4wvvpbgb9a-crates-io/rand-0.7.0/src/lib.rs`.">
#
# The reference to /nix/store/...-crates-io/... causes a run-time dependency
# to the complete source code blowing up the Nix closure size for no good
# reason. If this argument is set to true (which is the default) the latter
# will be replaced by:
#
# <meta name="description" content="Source to the Rust file removed to reduce Nix closure size.">
#
# Which drops the run-time dependency on the crates-io source thereby
# significantly reducing the Nix closure size.
, removeReferencesToSrcFromDocs ? true
, name
, version
, rustc
@ -176,6 +192,13 @@ with rec
echo " ${cargoDoc}"
${cargoDoc}
${lib.optionalString removeReferencesToSrcFromDocs ''
# Remove references to the source derivation to reduce closure size
match='<meta name="description" content="Source to the Rust file `${builtins.storeDir}[^`]*`.">'
replacement='<meta name="description" content="Source to the Rust file removed to reduce Nix closure size.">'
find target/doc -name "*\.rs\.html" -exec sed -i "s|$match|$replacement|" {} +
''}
runHook postDoc
'';