nlewo / nix2container

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

idea: Group image actions under `do` #117

Open kolloch opened 6 months ago

kolloch commented 6 months ago

I really like the idea of defining "convenience actions" on an image. Right now, though, they are mixed on the same level as unrelated attributes of a derivation.

n2c.aarch64-darwin.images.bash.result is an image produced with buildImage:

❯ nix run .\#n2c.aarch64-darwin.images.bash.result.<tab>
.\#n2c.aarch64-darwin.images.bash.result.__ignoreNulls                .\#n2c.aarch64-darwin.images.bash.result.enableParallelChecking
.\#n2c.aarch64-darwin.images.bash.result.__structuredAttrs            .\#n2c.aarch64-darwin.images.bash.result.enableParallelInstalling
.\#n2c.aarch64-darwin.images.bash.result.all                          .\#n2c.aarch64-darwin.images.bash.result.fromImage
.\#n2c.aarch64-darwin.images.bash.result.args                         .\#n2c.aarch64-darwin.images.bash.result.imageName
...

I propose to bundle the actions under a passthrough sub attribute do, maybe further subdivided into categories:

❯ nix run .\#someImage.do.<tab>
.\#someImage.do.copy  .\#someImage.do.run

and then

❯ nix run .\#someImage.do.copy.to<tab>
.\#someImage.do.copy.to              .\#someImage.do.copy.toPodman
.\#someImage.do.copy.toDockerDaemon  .\#someImage.do.copy.toRegistry

Compatibility: I'd keep aliases at the old locations for now. Potentially with a deprecation warning.

What do you think?

nlewo commented 6 months ago

I also like this idea. This goes a step further than my initial implementation (image.copyTo*) which i implemented for testing purposes... it seems people are no longer using it only for testing purposes :sweat_smile:

Do you know if this pattern is used elsewhere in the Nix community?

kolloch commented 6 months ago

I don’t know of other similar patterns in the nix community.

kolloch commented 6 months ago

I asked in a chat and there are some concerns using passthrough methods of derivations. The evaluation time accessing these methods apparently is significant (not verified).

in a flake module it is probably wiser to create a “do”sibling attribute next to the derivation of the image. For your API, you could do something similar but it would be a breaking change and in some contexts not feel as convenient, I think,

kolloch commented 6 months ago

If you keep the pass through methods, collecting them under a do super attribute is still a good idea, I think