Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 24.11] nixos/oci-containers: option to set the service name of a oci-ontainer #370887

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading