containerd.nix (1971B)
1 { config, lib, pkgs, ... }: 2 let 3 cfg = config.virtualisation.mycontainerd; 4 5 inherit (lib) mkOption types mkIf; 6 in 7 { 8 options.virtualisation.mycontainerd = { 9 enable = mkOption { 10 type = types.bool; 11 default = false; 12 description = '' 13 This option enables containerd, a daemon that manages linux containers. 14 ''; 15 }; 16 17 autostart = mkOption { 18 type = types.bool; 19 default = true; 20 description = '' 21 Start containerd automatically. 22 ''; 23 }; 24 25 package = mkOption { 26 default = pkgs.containerd; 27 type = types.package; 28 example = pkgs.containerd; 29 description = '' 30 Containerd package to be used in the module 31 ''; 32 }; 33 34 extraPackages = mkOption { 35 type = types.listOf types.package; 36 default = [ pkgs.runc pkgs.cni pkgs.cni-plugins ]; 37 description = "List of packages to be added to containerd service path"; 38 }; 39 40 extraOptions = mkOption { 41 type = types.separatedString " "; 42 default = ""; 43 description = 44 '' 45 The extra command-line options to pass to 46 <command>containerd</command> daemon. 47 ''; 48 }; 49 }; 50 51 config = mkIf cfg.enable { 52 environment.systemPackages = [ cfg.package ]; 53 systemd.packages = [ cfg.package ]; 54 55 systemd.services.containerd = { 56 wantedBy = lib.optional cfg.autostart [ "multi-user.target" ]; 57 serviceConfig = { 58 ExecStart = [ 59 "" 60 '' 61 ${cfg.package}/bin/containerd \ 62 ${cfg.extraOptions} 63 '' 64 ]; 65 }; 66 path = [ cfg.package ] ++ cfg.extraPackages; 67 }; 68 69 70 systemd.sockets.containerd = { 71 description = "Containerd Socket for the API"; 72 wantedBy = [ "sockets.target" ]; 73 socketConfig = { 74 ListenStream = "/run/containerd/containerd.sock"; 75 SocketMode = "0660"; 76 SocketUser = "root"; 77 SocketGroup = "root"; 78 }; 79 }; 80 81 }; 82 83 84 }