build-support: add strings-replace
tool
#22323
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces a tool called "strings-replace" that allow for a simple substitution of strings as as discovered by
Because this is a substitution of a null-terminated string into a binary, there's a fail-safe to make sure the substituted string is not longer than the original string.
This is my first commit to nixpkgs, and I read through all the contributors documentation. Hopefully I didn't miss anything, but I'm happy to make changes as recommended.
Motivation for this change
This is similar to
nuke-refs
, only not /nix/store specific. When attempting to make minimal closures, sometimes various build tools end up with hardcoded references to items in /nix/store.nuke-refs
is nice if these references are dead references. But sometimes, you want to move these files to another derivation and swap these new locations into the binary file.An example of this problem is Haskell Cabal, which has a feature called "data-files". For example, a popular Haskell monitoring library called
ekg
uses this feature to compile in references to web assets like HTML and Javascript files.We can have Cabal/GHC statically compile binaries to reduce the size of the transitive closure dramatically. But this doesn't help with strings compiled into the data-section of a binary.
This problem has been discussed in Gabriella439/haskell-nix#12 and #4504.
Even if Cabal/GHC were fixed such that this weren't needed for
ekg
, I think this might be a useful tool to have available. It's a sharp knife, though, so care must be exercised when using it.Things done
(nix.useSandbox on NixOS,
or option
build-use-sandbox
innix.conf
on non-NixOS)
nix-shell -p nox --run "nox-review wip"
./result/bin/
)