2014-07-28 00:00:59 +02:00
|
|
|
# Systemd services for docker.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.virtualisation.docker;
|
2014-12-01 17:20:18 +01:00
|
|
|
pro = config.networking.proxy.default;
|
|
|
|
proxy_env = optionalAttrs (pro != null) { Environment = "\"http_proxy=${pro}\""; };
|
2014-07-28 00:00:59 +02: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 23:24:17 +01: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-28 00:00:59 +02:00
|
|
|
mkOption {
|
|
|
|
type = types.bool;
|
2015-11-20 23:01:33 +01:00
|
|
|
default = true;
|
2014-07-28 00:00:59 +02:00
|
|
|
description =
|
|
|
|
''
|
2016-12-20 23:24:17 +01: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-28 00:00:59 +02:00
|
|
|
'';
|
|
|
|
};
|
2016-12-20 23:24:17 +01: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 01:18:19 +02:00
|
|
|
storageDriver =
|
|
|
|
mkOption {
|
2016-09-10 12:55:46 +02:00
|
|
|
type = types.nullOr (types.enum ["aufs" "btrfs" "devicemapper" "overlay" "overlay2" "zfs"]);
|
|
|
|
default = null;
|
2015-09-04 01:18:19 +02:00
|
|
|
description =
|
|
|
|
''
|
2016-09-10 12:55:46 +02:00
|
|
|
This option determines which Docker storage driver to use. By default
|
|
|
|
it let's docker automatically choose preferred storage driver.
|
2015-09-04 01:18:19 +02:00
|
|
|
'';
|
|
|
|
};
|
2016-09-10 12:55:46 +02: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-28 00:00:59 +02:00
|
|
|
extraOptions =
|
|
|
|
mkOption {
|
2015-04-25 15:25:15 +02:00
|
|
|
type = types.separatedString " ";
|
2014-07-28 00:00:59 +02:00
|
|
|
default = "";
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
The extra command-line options to pass to
|
|
|
|
<command>docker</command> daemon.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2016-12-24 01:44:10 +01:00
|
|
|
config = mkIf cfg.enable (mkMerge [{
|
|
|
|
environment.systemPackages = [ pkgs.docker ];
|
2014-09-03 21:22:20 +02:00
|
|
|
users.extraGroups.docker.gid = config.ids.gids.docker;
|
2016-12-24 01:44:10 +01:00
|
|
|
systemd.packages = [ pkgs.docker ];
|
|
|
|
|
2014-07-28 00:00:59 +02:00
|
|
|
systemd.services.docker = {
|
2016-12-20 23:24:17 +01:00
|
|
|
wantedBy = optional cfg.enableOnBoot "multi-user.target";
|
2014-07-28 00:00:59 +02:00
|
|
|
serviceConfig = {
|
2016-12-24 01:44:10 +01: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"
|
|
|
|
];
|
2014-11-07 12:46:36 +01:00
|
|
|
} // proxy_env;
|
2014-07-28 00:00:59 +02:00
|
|
|
|
2016-08-14 12:00:52 +02:00
|
|
|
path = [ pkgs.kmod ] ++ (optional (cfg.storageDriver == "zfs") pkgs.zfs);
|
2015-12-24 12:07:45 +01:00
|
|
|
};
|
2016-12-24 01:44:10 +01:00
|
|
|
systemd.sockets.docker.socketConfig.ListenStream = cfg.listenOptions;
|
2016-12-20 23:24:17 +01:00
|
|
|
}
|
2014-07-28 00:00:59 +02:00
|
|
|
]);
|
|
|
|
|
2017-01-01 09:01:03 +01:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule ["virtualisation" "docker" "socketActivation"] "This option was removed in favor of starting docker at boot")
|
|
|
|
];
|
|
|
|
|
2014-07-28 00:00:59 +02:00
|
|
|
}
|