2021-02-25 15:00:59 +00:00
|
|
|
{ pkgs, lib, config, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.containerd;
|
2021-06-01 06:26:42 +00:00
|
|
|
|
|
|
|
configFile = if cfg.configFile == null then
|
|
|
|
settingsFormat.generate "containerd.toml" cfg.settings
|
|
|
|
else
|
|
|
|
cfg.configFile;
|
|
|
|
|
|
|
|
containerdConfigChecked = pkgs.runCommand "containerd-config-checked.toml" {
|
|
|
|
nativeBuildInputs = [ pkgs.containerd ];
|
|
|
|
} ''
|
|
|
|
containerd -c ${configFile} config dump >/dev/null
|
|
|
|
ln -s ${configFile} $out
|
2021-02-25 15:00:59 +00:00
|
|
|
'';
|
2021-06-01 06:26:42 +00:00
|
|
|
|
|
|
|
settingsFormat = pkgs.formats.toml {};
|
2021-02-25 15:00:59 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options.virtualisation.containerd = with lib.types; {
|
|
|
|
enable = lib.mkEnableOption "containerd container runtime";
|
|
|
|
|
|
|
|
configFile = lib.mkOption {
|
|
|
|
default = null;
|
2021-06-01 06:26:42 +00:00
|
|
|
description = ''
|
|
|
|
Path to containerd config file.
|
|
|
|
Setting this option will override any configuration applied by the settings option.
|
|
|
|
'';
|
2021-02-25 15:00:59 +00:00
|
|
|
type = nullOr path;
|
|
|
|
};
|
|
|
|
|
2021-06-01 06:26:42 +00:00
|
|
|
settings = lib.mkOption {
|
|
|
|
type = settingsFormat.type;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Verbatim lines to add to containerd.toml
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-02-25 15:00:59 +00:00
|
|
|
args = lib.mkOption {
|
|
|
|
default = {};
|
|
|
|
description = "extra args to append to the containerd cmdline";
|
|
|
|
type = attrsOf str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-06-01 06:26:42 +00:00
|
|
|
warnings = lib.optional (cfg.configFile != null) ''
|
|
|
|
`virtualisation.containerd.configFile` is deprecated. use `virtualisation.containerd.settings` instead.
|
|
|
|
'';
|
|
|
|
|
|
|
|
virtualisation.containerd = {
|
|
|
|
args.config = toString containerdConfigChecked;
|
|
|
|
settings = {
|
2022-02-05 23:44:34 +00:00
|
|
|
version = 2;
|
2021-09-22 22:18:58 +00:00
|
|
|
plugins."io.containerd.grpc.v1.cri" = {
|
|
|
|
containerd.snapshotter =
|
|
|
|
lib.mkIf config.boot.zfs.enabled (lib.mkOptionDefault "zfs");
|
|
|
|
cni.bin_dir = lib.mkOptionDefault "${pkgs.cni-plugins}/bin";
|
|
|
|
};
|
2021-06-01 06:26:42 +00:00
|
|
|
};
|
|
|
|
};
|
2021-02-25 15:00:59 +00:00
|
|
|
|
2021-06-01 06:26:42 +00:00
|
|
|
environment.systemPackages = [ pkgs.containerd ];
|
2021-02-25 15:00:59 +00:00
|
|
|
|
|
|
|
systemd.services.containerd = {
|
|
|
|
description = "containerd - container runtime";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
path = with pkgs; [
|
|
|
|
containerd
|
|
|
|
runc
|
|
|
|
iptables
|
2021-06-01 06:26:42 +00:00
|
|
|
] ++ lib.optional config.boot.zfs.enabled config.boot.zfs.package;
|
2021-02-25 15:00:59 +00:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''${pkgs.containerd}/bin/containerd ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} cfg.args)}'';
|
|
|
|
Delegate = "yes";
|
|
|
|
KillMode = "process";
|
|
|
|
Type = "notify";
|
|
|
|
Restart = "always";
|
2021-05-10 10:08:56 +00:00
|
|
|
RestartSec = "10";
|
2021-02-25 15:00:59 +00:00
|
|
|
|
|
|
|
# "limits" defined below are adopted from upstream: https://github.com/containerd/containerd/blob/master/containerd.service
|
|
|
|
LimitNPROC = "infinity";
|
|
|
|
LimitCORE = "infinity";
|
|
|
|
TasksMax = "infinity";
|
|
|
|
OOMScoreAdjust = "-999";
|
2021-05-10 10:01:10 +00:00
|
|
|
|
|
|
|
StateDirectory = "containerd";
|
|
|
|
RuntimeDirectory = "containerd";
|
2021-07-29 14:58:23 +00:00
|
|
|
RuntimeDirectoryPreserve = "yes";
|
2021-02-25 15:00:59 +00:00
|
|
|
};
|
2021-05-10 10:08:56 +00:00
|
|
|
unitConfig = {
|
|
|
|
StartLimitBurst = "16";
|
|
|
|
StartLimitIntervalSec = "120s";
|
|
|
|
};
|
2021-02-25 15:00:59 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|