diff --git a/nixos/modules/virtualisation/oci-containers.nix b/nixos/modules/virtualisation/oci-containers.nix index 161b4f6027b2f..382e8ecb085a8 100644 --- a/nixos/modules/virtualisation/oci-containers.nix +++ b/nixos/modules/virtualisation/oci-containers.nix @@ -8,7 +8,8 @@ let defaultBackend = options.virtualisation.oci-containers.backend.default; containerOptions = - { ... }: { + { name, ... }: + { options = { @@ -52,6 +53,13 @@ let example = literalExpression "pkgs.dockerTools.streamLayeredImage {...};"; }; + serviceName = mkOption { + type = types.str; + default = "${cfg.backend}-${name}"; + defaultText = "-"; + description = "Systemd service name that manages the container"; + }; + login = { username = mkOption { @@ -412,20 +420,22 @@ in { }; - config = lib.mkIf (cfg.containers != {}) (lib.mkMerge [ - { - systemd.services = mapAttrs' (n: v: nameValuePair "${cfg.backend}-${n}" (mkService n v)) cfg.containers; + config = lib.mkIf (cfg.containers != { }) ( + lib.mkMerge [ + { + systemd.services = mapAttrs' (n: v: nameValuePair v.serviceName (mkService n v)) cfg.containers; + - assertions = - let - toAssertion = _: { imageFile, imageStream, ... }: - { assertion = imageFile == null || imageStream == null; + assertions = + let + toAssertion = _: { imageFile, imageStream, ... }: + { assertion = imageFile == null || imageStream == null; - message = "You can only define one of imageFile and imageStream"; - }; + message = "You can only define one of imageFile and imageStream"; + }; - in - lib.mapAttrsToList toAssertion cfg.containers; + in + lib.mapAttrsToList toAssertion cfg.containers; } (lib.mkIf (cfg.backend == "podman") { virtualisation.podman.enable = true;