- Click Files ⋮ > Show hidden files
- Add to the
replit.nix
file, before the closing}
:
env = {
C_INCLUDE_PATH = "${pkgs.libxml2.dev}/include/libxml2";
};
- Run in shell:
{
sed -i '/^override C/s/$/ -lxml2/' Makefile
pkill ccls
}
How did I get the code for #2?
Do read this so you can hopefully add packages in future by yourself
First, I search for the package on search.nixos.org.
I add .dev
at the end because this is what you do when
- you want a header
- and you see a
dev
output in the search result on search.nixos.org.
Adding to the deps
as with curl
doesn’t work: this library is packaged weirdly so the actual library that you have to include is within a subfolder of /include
(/include/libxml2
).
How did I know that?
I want to inspect the package’s contents. First I add to replit.nix
:
env = {
XML = "${pkgs.libxml2.dev}/include";
}
Our include starts with libxml/
, so we want to be able to include a libxml
folder, so in Shell, I run:
PROMPT_COMMAND='cd $XML
shopt -s globstar
echo **/libxml/
exit'
Output: libxml2/libxml
. So, when I add libxml/
to the $C_INCLUDE_PATH
, I must add /include/libxml2
. I change the env
section to:
C_INCLUDE_PATH = "${pkgs.libxml2.dev}/include/libxml2";
When I want to add another library that’s packaged weirdly and can’t be added through deps
, I have to add a :
before the next path, e.g.
C_INCLUDE_PATH = "${pkgs.libxml2.dev}/include/libxml2:${pkgs.SDL2.dev}/include/SDL2";
You can usually use builtins, string functions and with
to simplify this when it becomes too long and repetitive. A good example.