Skip to content

Conversation

@will-lol
Copy link
Contributor

@will-lol will-lol commented Sep 27, 2025

Description

Adds docker-cli.contexts support. This allows declarative configuration of docker contexts.

Checklist

  • Change is backwards compatible.

  • Code formatted with nix fmt or
    nix-shell -p treefmt nixfmt deadnix keep-sorted --run treefmt.

  • Code tested through nix run .#tests -- test-all or
    nix-shell --pure tests -A run.all.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.
    • Generate a news entry. See News
    • Basic tests added. See Tests
  • If this PR adds an exciting new feature or contains a breaking change.

    • Generate a news entry. See News

@will-lol will-lol force-pushed the docker-context branch 2 times, most recently from 8bc86cf to f13cb7c Compare September 27, 2025 23:47
Copy link
Collaborator

@khaneliman khaneliman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@FriedrichAltheide
Copy link
Contributor

@will-lol Each docker context must have a unique name right? If yes, I wonder if it might be better if the context name would be used as a key. E.g.:

contexts = {
   default = {
     Metadata = {
     ...
     };
     Endpoints = {
        docker = {
          Host = "unix://example2";
        };
      };
   secondContext = {
     Metadata = {
     ...
     };
     Endpoints = {
        docker = {
          Host = "unix://example2";
        };
      };
   }
};

How many options can be set, inside a context? Is the number limited? If yes, we could consider adding them all as options.

@will-lol
Copy link
Contributor Author

will-lol commented Sep 28, 2025

Hey @FriedrichAltheide. I can't for the life of me find any schema or actual helpful documentation about docker contexts. So I'm honestly not sure what can be set now, or how that will change in the future. I think to reduce our maintenance burden, it would be better to leave as json format.
Yes the names must be unique. Having an attrset of contexts (rather than a list), and using the keys as the name makes good sense to me.

@will-lol
Copy link
Contributor Author

will-lol commented Sep 30, 2025

@FriedrichAltheide I have switched to using an attrset as per your advice:

    programs.docker-cli.contexts = {
      colima = {
        Metadata = {
          Description = "Colima container runtime";
        };
        Endpoints.docker.Host = "unix://${config.home.homeDirectory}/.colima/default/docker.sock";
      };
    };

It supports the Name attribute as well if it is specified.

@will-lol will-lol mentioned this pull request Oct 1, 2025
9 tasks
@khaneliman
Copy link
Collaborator

sorry, can you rebase to fix ci issue

@will-lol will-lol force-pushed the docker-context branch 2 times, most recently from 24729e9 to 820bfe6 Compare October 7, 2025 05:51
@khaneliman khaneliman merged commit 990e5ce into nix-community:master Oct 14, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants