nlewo / nix2container

An archive-less dockerTools.buildImage implementation
Apache License 2.0
501 stars 45 forks source link

Fixes #92: Make nix-user example work (including flakes) #93

Closed kolloch closed 6 months ago

kolloch commented 10 months ago

Makes executing nix within the nix-user container possible :)

/thirdparty/nix2container master                                                                                                                                       base 14:27:00
❯ nix run .\#examples.nix-user.copyToDockerDaemon && docker run -it nix-user:latest
Copy to Docker daemon image nix-user:latest
Getting image source signatures
Copying blob a24921896e21 done  
Copying config ff83ffb7fb done  
Writing manifest to image destination
Running checks against store uri: local
[PASS] PATH contains only one nix version.
[PASS] All profiles are gcroots.
[PASS] Client protocol matches store protocol.
[INFO] You are trusted by store uri: local
total 24
drwxr-xr-x  1 user user 4096 Jan  1  1970 .
drwxr-xr-x  1    0    0 4096 Nov  3 13:28 ..
drwxr-xr-x 54 user user 4096 Jan  1  1970 store
drwxr-xr-x  1 user user 4096 Jan  1  1970 var
bash-5.2$ nix run nixpkgs#hello
Hello, world!
bash-5.2$ 
kolloch commented 10 months ago

Sure! I don't mind to split it into another file.

To avoid misleading users such as me, I'd comment on the original file that some more steps are needed to make this work in practice. I mistook the example as a best practice recommendation and getting started basis.

If the "new" example will serve as the getting started basis, I'd keep adding to the nix.conf in there: It is a very common requirement if you want to build upon that example.

And I am all for tests. One think that might potentially make this difficult, is that for a meaninful test, you'd need to load the image into a docker runtime and execute some commands in it. Does your CI support that?

nlewo commented 10 months ago

I mistook the example as a best practice recommendation and getting started basis.

I'm sorry about this: this should no longer be in a example directory... Ideally we should have an example section and a test section but this kind of improvements takes time to implement :/ At least, currently, all "examples" are tested. (btw, +1 for a comment in this file).

If the "new" example will serve as the getting started basis, I'd keep adding to the nix.conf in there: It is a very common requirement if you want to build upon that example.

Agreed (and i'm also in favor of enabling flakes).

One think that might potentially make this difficult, is that for a meaninful test, you'd need to load the image into a docker runtime and execute some commands in it. Does your CI support that?

Yes, the CI does that... in an impure way (see this doc) but in practice it works pretty well (in the future, I'm planning to run this in a NixOS VM to make it pure).

kolloch commented 10 months ago

How shall I call the new directory then?

Or shall I rename examples to testImages or similar?