1 { pkgs, lib, config, ... }:
3 cfg = config.virtualisation.containerd;
5 configFile = if cfg.configFile == null then
6 settingsFormat.generate "containerd.toml" cfg.settings
10 containerdConfigChecked = pkgs.runCommand "containerd-config-checked.toml" {
11 nativeBuildInputs = [ pkgs.containerd ];
13 containerd -c ${configFile} config dump >/dev/null
14 ln -s ${configFile} $out
17 settingsFormat = pkgs.formats.toml {};
21 options.virtualisation.containerd = with lib.types; {
22 enable = lib.mkEnableOption "containerd container runtime";
24 configFile = lib.mkOption {
27 Path to containerd config file.
28 Setting this option will override any configuration applied by the settings option.
33 settings = lib.mkOption {
34 type = settingsFormat.type;
37 Verbatim lines to add to containerd.toml
43 description = "extra args to append to the containerd cmdline";
48 config = lib.mkIf cfg.enable {
49 warnings = lib.optional (cfg.configFile != null) ''
50 `virtualisation.containerd.configFile` is deprecated. use `virtualisation.containerd.settings` instead.
53 virtualisation.containerd = {
54 args.config = toString containerdConfigChecked;
57 plugins."io.containerd.grpc.v1.cri" = {
58 containerd.snapshotter =
59 lib.mkIf config.boot.zfs.enabled (lib.mkOptionDefault "zfs");
60 cni.bin_dir = lib.mkOptionDefault "${pkgs.cni-plugins}/bin";
65 environment.systemPackages = [ pkgs.containerd ];
67 systemd.services.containerd = {
68 description = "containerd - container runtime";
69 wantedBy = [ "multi-user.target" ];
70 after = [ "network.target" ];
75 ] ++ lib.optional config.boot.zfs.enabled config.boot.zfs.package;
77 ExecStart = ''${pkgs.containerd}/bin/containerd ${lib.concatStringsSep " " (lib.cli.toGNUCommandLine {} cfg.args)}'';
84 # "limits" defined below are adopted from upstream: https://github.com/containerd/containerd/blob/master/containerd.service
85 LimitNPROC = "infinity";
86 LimitCORE = "infinity";
87 TasksMax = "infinity";
88 OOMScoreAdjust = "-999";
90 StateDirectory = "containerd";
91 RuntimeDirectory = "containerd";
92 RuntimeDirectoryPreserve = "yes";
95 StartLimitBurst = "16";
96 StartLimitIntervalSec = "120s";