There’s a hole in my understanding and I’m having trouble finding documents to fill it in.
I wanted to try my hand at building simple packages, and that worked out okay, until I tried to then generate a docker container from the simple packages. It creates the container just fine, but dependencies are missing. I ripped out everything specific to what I was trying to package up and I’ll demonstrate it below with just python3 and including the magic library.
If I do something like nix-shell -p python3Packages.magic
then I can import magic
just fine in the resulting shell. But if I build a container like the following, the resulting container cannot import magic
.
{
lib,
stdenv,
}:
let
pkgs = import <nixpkgs> { config = {}; overlays = []; };
in pkgs.dockerTools.buildImage {
name = "stripped";
tag = "nix";
created = "now";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [pkgs.python3Minimal pkgs.python3Packages.magic];
};
config = {
cmd = [ "python" ];
};
}
When I docker image load -i result
and then docker run --rm -ti stripped:nix
…
# docker run --rm -ti stripped:nix python
Python 3.11.8 (main, Feb 6 2024, 21:21:21) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import magic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'magic'
Poking around the python shell a bit and using os.listdir I could see that the magic libraries indeed were not included in the container.
Anyone know what I’m doing wrong? Or able to piece together what I’m not understanding correctly?