Unverified Commit 265ca818 authored by Franz Pletz's avatar Franz Pletz Committed by GitHub
Browse files

Merge pull request #241908 from picnoir/nin/oci-container-pre-start-list

parents aebf2ca9 b7fd0226
Loading
Loading
Loading
Loading
+21 −18
Original line number Diff line number Diff line
@@ -239,21 +239,10 @@ let
  mkService = name: container: let
    dependsOn = map (x: "${cfg.backend}-${x}.service") container.dependsOn;
    escapedName = escapeShellArg name;
  in {
    wantedBy = [] ++ optional (container.autoStart) "multi-user.target";
    after = lib.optionals (cfg.backend == "docker") [ "docker.service" "docker.socket" ]
            # if imageFile is not set, the service needs the network to download the image from the registry
            ++ lib.optionals (container.imageFile == null) [ "network-online.target" ]
            ++ dependsOn;
    requires = dependsOn;
    environment = proxy_env;

    path =
      if cfg.backend == "docker" then [ config.virtualisation.docker.package ]
      else if cfg.backend == "podman" then [ config.virtualisation.podman.package ]
      else throw "Unhandled backend: ${cfg.backend}";

    preStart = ''
    preStartScript = pkgs.writeShellApplication {
      name = "pre-start";
      runtimeInputs = [ ];
      text = ''
        ${cfg.backend} rm -f ${name} || true
        ${optionalString (isValidLogin container.login) ''
          cat ${container.login.passwordFile} | \
@@ -269,6 +258,20 @@ let
          rm -f /run/podman-${escapedName}.ctr-id
        ''}
      '';
    };
  in {
    wantedBy = [] ++ optional (container.autoStart) "multi-user.target";
    after = lib.optionals (cfg.backend == "docker") [ "docker.service" "docker.socket" ]
            # if imageFile is not set, the service needs the network to download the image from the registry
            ++ lib.optionals (container.imageFile == null) [ "network-online.target" ]
            ++ dependsOn;
    requires = dependsOn;
    environment = proxy_env;

    path =
      if cfg.backend == "docker" then [ config.virtualisation.docker.package ]
      else if cfg.backend == "podman" then [ config.virtualisation.podman.package ]
      else throw "Unhandled backend: ${cfg.backend}";

    script = concatStringsSep " \\\n  " ([
      "exec ${cfg.backend} run"
@@ -318,7 +321,7 @@ let
      ###
      # ExecReload = ...;
      ###

      ExecStartPre = [ "${preStartScript}/bin/pre-start" ];
      TimeoutStartSec = 0;
      TimeoutStopSec = 120;
      Restart = "always";