Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker-containers: Add enableOnBoot option #76480

Merged
merged 1 commit into from Feb 14, 2020

Conversation

Atemu
Copy link
Member

@Atemu Atemu commented Dec 25, 2019

Motivation for this change

A user might want to declare a docker container that can be run on-demand but does not get started automatically on boot.

Resolves #73111.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

@@ -161,11 +161,20 @@ let
["--network=host"]
'';
};

enableOnBoot = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@Atemu Atemu Dec 25, 2019

Choose a reason for hiding this comment

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

I struggled with finding a good name for it (it's a programmers greatest enemy) and decided to follow https://nixos.org/nixos/options.html#virtualisation.docker.enableonboot in the end.
Thanks for pointing it out, I forgot to ask about the name in the PR.

@roberth
Copy link
Member

roberth commented Dec 28, 2019

Docker makes a distinction between container creation and container start, so an option called enableOnBoot is ambiguous. I'd go with startOnBoot.

Docker natively supports starting containers on boot via restart=always. The fact that this PR does it differently should be documented in the option description.
I do think it's a good choice to avoid exposing docker's restart policies. It seems better to split it into more options, e.g. startOnBoot, startOnExit, startOnFailure (no effect if startOnExit is true).

So I think startOnBoot is a more consistent name.

EDIT: the other options I named don't have to be included in this PR necessarily.

@Atemu
Copy link
Member Author

Atemu commented Dec 28, 2019

docker-containers doesn't use the dockerd to start the containers on boot, it uses systemd services. Using Docker's terminology for it would be a bit confusing.
Same goes for restart policies, those are systemd's too (see #76479).

I think @danbst's suggestion is what we should go with, it's unambiguous and matches what nixos-containers use.

@roberth
Copy link
Member

roberth commented Dec 28, 2019

Using Docker's terminology for it [docker-containers] would be a bit confusing.

Interesting.

it uses systemd services.
Same goes for restart policies, those are systemd's too

Sure, but should a user of this module care about these implementation details?

it's unambiguous

No it's not. The OnBoot suffix indicates that what precedes it is an operation to be performed at system boot time. However, "enable" is not a defined operation on docker containers.

"Enable" is used in NixOS (a lot) to define things into existence (or inhibit their existence).

Suppose I have a container for a service that I only run when a certain event happens. Certainly this container has to be "enabled": I want it to be downloaded, held onto by the system and to be ready to run. However, it should not be started on boot, because it's designed to be triggered by my event.

@danbst
Copy link
Contributor

danbst commented Dec 28, 2019

startOnBoot or autoStart are both good names IMO. "enable" word is quite overused already.

@Atemu
Copy link
Member Author

Atemu commented Dec 30, 2019

Using Docker's terminology for it [docker-containers] would be a bit confusing.

Interesting.

Don't quote me out of context like that, the sentence only makes sense together with the one preceding it.

it uses systemd services.
Same goes for restart policies, those are systemd's too

Sure, but should a user of this module care about these implementation details?

If it directly affects how their configuration option makes their system behave, yes.

It should be documented however.

it's unambiguous

No it's not. The OnBoot suffix indicates that what precedes it is an operation to be performed at system boot time. However, "enable" is not a defined operation on docker containers.

"Enable" is used in NixOS (a lot) to define things into existence (or inhibit their existence).

@danbst's suggestion contains none of those words.

Suppose I have a container for a service that I only run when a certain event happens. Certainly this container has to be "enabled": I want it to be downloaded, held onto by the system and to be ready to run. However, it should not be started on boot, because it's designed to be triggered by my event.

A container being available to the system is implied when you declare it in your system configuration.

@roberth
Copy link
Member

roberth commented Dec 30, 2019

Don't quote me out of context like that,

I didn't mean to offend you and that was needlessly polarizing. We're on the same team :) (team Nix)

I'm trying to help you with naming, as you've indicated that it needed attention.

A container being available to the system is implied when you declare it in your system configuration.

Yes, always creating the container is a good idea (or good default*). What should be configurable is after which events to start it.

(* An enable option to inhibit even the creation, analogous to https://nixos.org/nixos/options.html#systemd.services.%3Cname%3E.enable might make sense, but that's speculative at this point.)

@Atemu
Copy link
Member Author

Atemu commented Dec 30, 2019

I didn't mean to offend you and that was needlessly polarizing. We're on the same team :) (team Nix)

I'm not offended, no worries.
I was arguing against an argumentation/comment that I thought was poor because it tried to argue against an argument taken out of context and thereby robbed of its sense.
Whose argument it was against and who made it don't matter to me.

I'm trying to help you with naming, as you've indicated that it needed attention.

You're more than welcome to do and continue doing that as far as I'm concerned.

Yes, always creating the container is a good idea (or good default*). What should be configurable is after which events to start it.

That's exactly right and made me think of a good point just now: This PR's option is only binary.
Maybe it'd be better to make the whole WantedBy configurable with [ multi-user.target ] as the default.

(* An enable option to inhibit even the creation, analogous to https://nixos.org/nixos/options.html#systemd.services.%3Cname%3E.enable might make sense, but that's speculative at this point.)

Might be a good idea to open a separate issue/PR for that option.

@Atemu Atemu force-pushed the docker-containers-enableOnBoot branch from ebff997 to 1a6bb32 Compare February 7, 2020 12:57
This option allows the user to control whether or not the docker container is
automatically started on boot. The previous default behavior (true) is preserved
@Atemu Atemu force-pushed the docker-containers-enableOnBoot branch from 1a6bb32 to 5399f9b Compare February 7, 2020 13:15
@danbst danbst merged commit 08ac06e into NixOS:master Feb 14, 2020
@danbst
Copy link
Contributor

danbst commented Feb 14, 2020

@Atemu thanks, finally got hands to test this, works fine

dtzWill pushed a commit to dtzWill/nixpkgs that referenced this pull request Feb 15, 2020
This option allows the user to control whether or not the docker container is
automatically started on boot. The previous default behavior (true) is preserved

(cherry picked from commit 08ac06e)
@Atemu Atemu deleted the docker-containers-enableOnBoot branch July 30, 2020 12:53
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.

Declarative Docker containers are always wanted by multi-user.target
3 participants