2023-01-11 07:51:40 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
|
|
|
cfg = config.virtualisation.containers;
|
|
|
|
|
2021-10-06 13:57:05 +00:00
|
|
|
inherit (lib) literalExpression mkOption types;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
toml = pkgs.formats.toml { };
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
meta = {
|
2022-08-21 13:32:41 +00:00
|
|
|
maintainers = [ ] ++ lib.teams.podman.members;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
options.virtualisation.containers = {
|
|
|
|
|
|
|
|
enable =
|
|
|
|
mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
This option enables the common /etc/containers configuration module.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
ociSeccompBpfHook.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable the OCI seccomp BPF hook";
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
cdi = {
|
|
|
|
dynamic.nvidia.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Enable dynamic CDI configuration for NVidia devices by running nvidia-container-toolkit on boot.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
static = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
default = { };
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Declarative CDI specification. Each key of the attribute set
|
|
|
|
will be mapped to a file in /etc/cdi. It is required for every
|
|
|
|
key to be provided in JSON format.
|
|
|
|
'';
|
|
|
|
example = {
|
|
|
|
some-vendor = builtins.fromJSON ''
|
|
|
|
{
|
|
|
|
"cdiVersion": "0.5.0",
|
|
|
|
"kind": "some-vendor.com/foo",
|
|
|
|
"devices": [],
|
|
|
|
"containerEdits": []
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
some-other-vendor = {
|
|
|
|
cdiVersion = "0.5.0";
|
|
|
|
kind = "some-other-vendor.com/bar";
|
|
|
|
devices = [];
|
|
|
|
containerEdits = [];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
containersConf.settings = mkOption {
|
|
|
|
type = toml.type;
|
|
|
|
default = { };
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "containers.conf configuration";
|
2020-07-18 16:06:22 +00:00
|
|
|
};
|
|
|
|
|
2021-06-04 09:07:49 +00:00
|
|
|
containersConf.cniPlugins = mkOption {
|
|
|
|
type = types.listOf types.package;
|
2021-10-06 13:57:05 +00:00
|
|
|
defaultText = literalExpression ''
|
2021-06-04 09:07:49 +00:00
|
|
|
[
|
|
|
|
pkgs.cni-plugins
|
|
|
|
]
|
|
|
|
'';
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2021-06-04 09:07:49 +00:00
|
|
|
[
|
|
|
|
pkgs.cniPlugins.dnsname
|
|
|
|
]
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-06-04 09:07:49 +00:00
|
|
|
CNI plugins to install on the system.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-06-06 07:54:09 +00:00
|
|
|
storage.settings = mkOption {
|
|
|
|
type = toml.type;
|
|
|
|
default = {
|
|
|
|
storage = {
|
|
|
|
driver = "overlay";
|
|
|
|
graphroot = "/var/lib/containers/storage";
|
|
|
|
runroot = "/run/containers/storage";
|
|
|
|
};
|
|
|
|
};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "storage.conf configuration";
|
2021-06-06 07:54:09 +00:00
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
registries = {
|
|
|
|
search = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "docker.io" "quay.io" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
List of repositories to search.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
insecure = mkOption {
|
2022-08-21 13:32:41 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
List of insecure repositories.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
block = mkOption {
|
2022-08-21 13:32:41 +00:00
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.listOf types.str;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
List of blocked repositories.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
policy = mkOption {
|
2022-08-21 13:32:41 +00:00
|
|
|
default = { };
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.attrs;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression ''
|
2020-04-24 23:36:52 +00:00
|
|
|
{
|
|
|
|
default = [ { type = "insecureAcceptAnything"; } ];
|
|
|
|
transports = {
|
|
|
|
docker-daemon = {
|
|
|
|
"" = [ { type = "insecureAcceptAnything"; } ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Signature verification policy file.
|
|
|
|
If this option is empty the default policy file from
|
2022-08-12 12:06:08 +00:00
|
|
|
`skopeo` will be used.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
2021-06-04 09:07:49 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
hardware.nvidia-container-toolkit-cdi-generator.enable = lib.mkIf cfg.cdi.dynamic.nvidia.enable true;
|
|
|
|
|
2021-06-04 09:07:49 +00:00
|
|
|
virtualisation.containers.containersConf.cniPlugins = [ pkgs.cni-plugins ];
|
|
|
|
|
2021-04-12 18:23:04 +00:00
|
|
|
virtualisation.containers.containersConf.settings = {
|
2021-06-04 09:07:49 +00:00
|
|
|
network.cni_plugin_dirs = map (p: "${lib.getBin p}/bin") cfg.containersConf.cniPlugins;
|
2021-04-12 18:23:04 +00:00
|
|
|
engine = {
|
|
|
|
init_path = "${pkgs.catatonit}/bin/catatonit";
|
|
|
|
} // lib.optionalAttrs cfg.ociSeccompBpfHook.enable {
|
|
|
|
hooks_dir = [ config.boot.kernelPackages.oci-seccomp-bpf-hook ];
|
|
|
|
};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
environment.etc = let
|
|
|
|
cdiStaticConfigurationFiles = (lib.attrsets.mapAttrs'
|
|
|
|
(name: value:
|
|
|
|
lib.attrsets.nameValuePair "cdi/${name}.json"
|
|
|
|
{ text = builtins.toJSON value; })
|
|
|
|
cfg.cdi.static);
|
|
|
|
in {
|
|
|
|
"containers/containers.conf".source =
|
|
|
|
toml.generate "containers.conf" cfg.containersConf.settings;
|
|
|
|
|
|
|
|
"containers/storage.conf".source =
|
|
|
|
toml.generate "storage.conf" cfg.storage.settings;
|
|
|
|
|
|
|
|
"containers/registries.conf".source = toml.generate "registries.conf" {
|
|
|
|
registries = lib.mapAttrs (n: v: { registries = v; }) cfg.registries;
|
|
|
|
};
|
2021-06-06 07:54:09 +00:00
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
"containers/policy.json".source =
|
|
|
|
if cfg.policy != { } then pkgs.writeText "policy.json" (builtins.toJSON cfg.policy)
|
|
|
|
else "${pkgs.skopeo.policy}/default-policy.json";
|
|
|
|
} // cdiStaticConfigurationFiles;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|