Skip to content

Commit

Permalink
[Backport 24.11] nixos/oci-containers: option to set the service name…
Browse files Browse the repository at this point in the history
… of a oci-ontainer (#370887)
  • Loading branch information
GaetanLepage authored Jan 4, 2025
2 parents 8e419ad + 6b580e7 commit 8f1fa8d
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions nixos/modules/virtualisation/oci-containers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let
defaultBackend = options.virtualisation.oci-containers.backend.default;

containerOptions =
{ ... }: {
{ name, ... }:
{

options = {

Expand Down Expand Up @@ -52,6 +53,13 @@ let
example = literalExpression "pkgs.dockerTools.streamLayeredImage {...};";
};

serviceName = mkOption {
type = types.str;
default = "${cfg.backend}-${name}";
defaultText = "<backend>-<name>";
description = "Systemd service name that manages the container";
};

login = {

username = mkOption {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8f1fa8d

Please sign in to comment.