Flake example for mkDockerImage from mach-nix

Does someone have an example for mkDockerImage from mach-nix?
I was able to get the basic image building but wasn’t successful with the overrides described here:

Edit:
To give a bit more context, with the following flake I can execute nix build and get a result which I can load with docker:

In what way did the overrides not succeed? I did get one of these working recently (but it wasn’t a flake, and I can’t post it all).

I just wasn’t able to get it to work at all with the provided example due to syntax errors.
I reckon it has to look different in a flake?
I can build the container when I use it without the override so that part works.

1 Like

I added my current WIP to the top post.

I think maybe that helps…

If I’m understanding right, the WIP in your post is the working version. From the location you linked to, I’m guessing you want to apply something like:

image.override (oldAttrs: {
  name = "jupyterlab";
  config.Cmd = [ "jupyter" "lab" "--notebook-dir=/mnt" "--allow-root" "--ip=0.0.0.0" ];
})

You are having syntax errors, but haven’t posted which errors or the source causing them, so I can only guess. You need to call override on the result of mkDockerImage (directly, or via the defaultPackage attr).

If you’re trying to do it directly, I think you’d need parentheses to group it properly… probably (I’m shooting from the hip…):

        defaultPackage = (machNix.mkDockerImage {
          requirements = builtins.readFile ./requirements/docker.txt;
          _.pytest-cov.propagatedBuildInputs.mod = pySelf: self: oldVal: oldVal ++ [ pySelf.tomli ];
        }).override (<should be able to parrot what the mach-nix doc says here>);

Thank you I got it working this way.
Sorry for not posting the full flake.nix and error I got.
I tried so many things that I really was just looking for a working example.

Next step is now to figure out how to use my run script from before :slight_smile:

1 Like