2014-07-27 23:00:59 +01:00
|
|
|
# Systemd services for docker.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.virtualisation.docker;
|
2017-04-26 15:55:36 +01:00
|
|
|
proxy_env = config.networking.proxy.envVars;
|
2014-07-27 23:00:59 +01:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.virtualisation.docker = {
|
|
|
|
enable =
|
|
|
|
mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
This option enables docker, a daemon that manages
|
|
|
|
linux containers. Users in the "docker" group can interact with
|
|
|
|
the daemon (e.g. to start or stop containers) using the
|
|
|
|
<command>docker</command> command line tool.
|
|
|
|
'';
|
|
|
|
};
|
2016-12-20 22:24:17 +00:00
|
|
|
|
|
|
|
listenOptions =
|
|
|
|
mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = ["/var/run/docker.sock"];
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
A list of unix and tcp docker should listen to. The format follows
|
|
|
|
ListenStream as described in systemd.socket(5).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableOnBoot =
|
2014-07-27 23:00:59 +01:00
|
|
|
mkOption {
|
|
|
|
type = types.bool;
|
2015-11-20 22:01:33 +00:00
|
|
|
default = true;
|
2014-07-27 23:00:59 +01:00
|
|
|
description =
|
|
|
|
''
|
2016-12-20 22:24:17 +00:00
|
|
|
When enabled dockerd is started on boot. This is required for
|
|
|
|
container, which are created with the
|
|
|
|
<literal>--restart=always</literal> flag, to work. If this option is
|
|
|
|
disabled, docker might be started on demand by socket activation.
|
2014-07-27 23:00:59 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-12-20 22:24:17 +00:00
|
|
|
|
|
|
|
liveRestore =
|
|
|
|
mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
Allow dockerd to be restarted without affecting running container.
|
|
|
|
This option is incompatible with docker swarm.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-09-04 00:18:19 +01:00
|
|
|
storageDriver =
|
|
|
|
mkOption {
|
2016-09-10 11:55:46 +01:00
|
|
|
type = types.nullOr (types.enum ["aufs" "btrfs" "devicemapper" "overlay" "overlay2" "zfs"]);
|
|
|
|
default = null;
|
2015-09-04 00:18:19 +01:00
|
|
|
description =
|
|
|
|
''
|
2016-09-10 11:55:46 +01:00
|
|
|
This option determines which Docker storage driver to use. By default
|
|
|
|
it let's docker automatically choose preferred storage driver.
|
2015-09-04 00:18:19 +01:00
|
|
|
'';
|
|
|
|
};
|
2016-09-10 11:55:46 +01:00
|
|
|
|
|
|
|
logDriver =
|
|
|
|
mkOption {
|
|
|
|
type = types.enum ["none" "json-file" "syslog" "journald" "gelf" "fluentd" "awslogs" "splunk" "etwlogs" "gcplogs"];
|
|
|
|
default = "journald";
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
This option determines which Docker log driver to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-07-27 23:00:59 +01:00
|
|
|
extraOptions =
|
|
|
|
mkOption {
|
2015-04-25 14:25:15 +01:00
|
|
|
type = types.separatedString " ";
|
2014-07-27 23:00:59 +01:00
|
|
|
default = "";
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
The extra command-line options to pass to
|
|
|
|
<command>docker</command> daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2016-12-24 00:44:10 +00:00
|
|
|
config = mkIf cfg.enable (mkMerge [{
|
|
|
|
environment.systemPackages = [ pkgs.docker ];
|
2014-09-03 20:22:20 +01:00
|
|
|
users.extraGroups.docker.gid = config.ids.gids.docker;
|
2016-12-24 00:44:10 +00:00
|
|
|
systemd.packages = [ pkgs.docker ];
|
|
|
|
|
2014-07-27 23:00:59 +01:00
|
|
|
systemd.services.docker = {
|
2016-12-20 22:24:17 +00:00
|
|
|
wantedBy = optional cfg.enableOnBoot "multi-user.target";
|
2017-04-26 15:55:36 +01:00
|
|
|
environment = proxy_env;
|
2014-07-27 23:00:59 +01:00
|
|
|
serviceConfig = {
|
2016-12-24 00:44:10 +00:00
|
|
|
ExecStart = [
|
|
|
|
""
|
|
|
|
''
|
|
|
|
${pkgs.docker}/bin/dockerd \
|
|
|
|
--group=docker \
|
|
|
|
--host=fd:// \
|
|
|
|
--log-driver=${cfg.logDriver} \
|
|
|
|
${optionalString (cfg.storageDriver != null) "--storage-driver=${cfg.storageDriver}"} \
|
|
|
|
${optionalString cfg.liveRestore "--live-restore" } \
|
|
|
|
${cfg.extraOptions}
|
|
|
|
''];
|
|
|
|
ExecReload=[
|
|
|
|
""
|
|
|
|
"${pkgs.procps}/bin/kill -s HUP $MAINPID"
|
|
|
|
];
|
2017-04-26 15:55:36 +01:00
|
|
|
};
|
2014-07-27 23:00:59 +01:00
|
|
|
|
2016-08-14 11:00:52 +01:00
|
|
|
path = [ pkgs.kmod ] ++ (optional (cfg.storageDriver == "zfs") pkgs.zfs);
|
2015-12-24 11:07:45 +00:00
|
|
|
};
|
2017-03-27 14:11:44 +01:00
|
|
|
|
|
|
|
systemd.sockets.docker = {
|
|
|
|
description = "Docker Socket for the API";
|
|
|
|
wantedBy = [ "sockets.target" ];
|
|
|
|
socketConfig = {
|
|
|
|
ListenStream = cfg.listenOptions;
|
|
|
|
SocketMode = "0660";
|
|
|
|
SocketUser = "root";
|
|
|
|
SocketGroup = "docker";
|
|
|
|
};
|
|
|
|
};
|
2016-12-20 22:24:17 +00:00
|
|
|
}
|
2014-07-27 23:00:59 +01:00
|
|
|
]);
|
|
|
|
|
2017-01-01 08:01:03 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule ["virtualisation" "docker" "socketActivation"] "This option was removed in favor of starting docker at boot")
|
|
|
|
];
|
|
|
|
|
2014-07-27 23:00:59 +01:00
|
|
|
}
|