git.iko.soy/typeable/nixpkgs
on master help sign in
docker module: fix kernel module loading

The docker module used different code for socket-activated docker daemon than for the non-socket activated daemon. In particular, if the socket-activated daemon is used, then modprobe wasn't set up to be usable and in PATH for the docker daemon, which resulted in a failure to start the daemon with overlayfs as storageDriver if the `overlay` kernel module wasn't already loaded. This commit fixes that bug (which only appears if socket activation is used), and also reduces the duplication between code paths so that it's easier to keep both in sync in future.

commit79b4e5a8d7efe534647e2d5287f606883fc555a3 authorBenno Fünfstück <benno.fuenfstueck@gmail.com> dateThu 24 Dec 2015, 12:07 (11 years ago) parent0fda4ff
1 file changed+16−31
nixos/modules/virtualisation/docker.nix+16−31
nixos/modules/virtualisation/docker.nix+16−31
@@ -69,7 +69,8 @@ in
6969 description = ''
7070 The postStart phase of the systemd service. You may need to
7171 override this if you are passing in flags to docker which
72− don't cause the socket file to be created.
72+ don't cause the socket file to be created. This option is ignored
73+ if socket activation is used.
7374 '';
7475 };
7576
@@ -81,22 +82,29 @@ in
8182 config = mkIf cfg.enable (mkMerge [
8283 { environment.systemPackages = [ pkgs.docker ];
8384 users.extraGroups.docker.gid = config.ids.gids.docker;
84− }
85− (mkIf cfg.socketActivation {
86−
8785 systemd.services.docker = {
8886 description = "Docker Application Container Engine";
89− after = [ "network.target" "docker.socket" ];
90− requires = [ "docker.socket" ];
87+ wantedBy = optional (!cfg.socketActivation) "multi-user.target";
88+ after = [ "network.target" ] ++ (optional cfg.socketActivation "docker.socket") ;
89+ requires = optional cfg.socketActivation "docker.socket";
9190 serviceConfig = {
92− ExecStart = "${pkgs.docker}/bin/docker daemon --host=fd:// --group=docker --storage-driver=${cfg.storageDriver} ${cfg.extraOptions}";
91+ ExecStart = "${pkgs.docker}/bin/docker daemon --group=docker --storage-driver=${cfg.storageDriver} ${optionalString cfg.socketActivation "--host=fd://"} ${cfg.extraOptions}";
9392 # I'm not sure if that limits aren't too high, but it's what
9493 # goes in config bundled with docker itself
9594 LimitNOFILE = 1048576;
9695 LimitNPROC = 1048576;
9796 } // proxy_env;
98− };
9997
98+ path = [ pkgs.kmod ] ++ (optional (cfg.storageDriver == "zfs") pkgs.zfs);
99+ environment.MODULE_DIR = "/run/current-system/kernel-modules/lib/modules";
100+
101+ postStart = if cfg.socketActivation then "" else cfg.postStart;
102+
103+ # Presumably some containers are running we don't want to interrupt
104+ restartIfChanged = false;
105+ };
106+ }
107+ (mkIf cfg.socketActivation {
100108 systemd.sockets.docker = {
101109 description = "Docker Socket for the API";
102110 wantedBy = [ "sockets.target" ];
@@ -108,29 +116,6 @@ in
108116 };
109117 };
110118 })
111− (mkIf (!cfg.socketActivation) {
112−
113− systemd.services.docker = {
114− description = "Docker Application Container Engine";
115− wantedBy = [ "multi-user.target" ];
116− after = [ "network.target" ];
117− serviceConfig = {
118− ExecStart = "${pkgs.docker}/bin/docker daemon --group=docker --storage-driver=${cfg.storageDriver} ${cfg.extraOptions}";
119− # I'm not sure if that limits aren't too high, but it's what
120− # goes in config bundled with docker itself
121− LimitNOFILE = 1048576;
122− LimitNPROC = 1048576;
123− } // proxy_env;
124−
125− path = [ pkgs.kmod ] ++ (optional (cfg.storageDriver == "zfs") pkgs.zfs);
126− environment.MODULE_DIR = "/run/current-system/kernel-modules/lib/modules";
127−
128− postStart = cfg.postStart;
129−
130− # Presumably some containers are running we don't want to interrupt
131− restartIfChanged = false;
132− };
133− })
134119 ]);
135120
136121}