From d523a5c8e1cf00ec258af2a73cfcac69bae3c90c Mon Sep 17 00:00:00 2001 From: Christopher Bacher Date: Mon, 17 Oct 2022 01:17:29 +0200 Subject: [PATCH] modules(pihole-container): expliclitly stop the container with podman Currently the container often fails to startup again in a nixos-rebuild. Maybe this is because the container lingers a bit after the systemd.service has already been stopped and the container from the restarted service can't be created. The podman-stop command should delay the stopping of the service until the container is gone too. --- modules/pihole-container.factory.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/pihole-container.factory.nix b/modules/pihole-container.factory.nix index 0640251..275fb75 100644 --- a/modules/pihole-container.factory.nix +++ b/modules/pihole-container.factory.nix @@ -58,6 +58,14 @@ in rec { ''; }; + containerName = mkOption { + type = types.str; + description = '' + The name of the podman container in which pihole will be started. + ''; + default = "pihole_${cfg.hostConfig.user}"; + }; + persistVolumes = mkOption { type = types.bool; description = "Whether to use podman volumes to persist pihole's ad-hoc configuration across restarts."; @@ -316,7 +324,7 @@ in rec { ${pkgs.podman}/bin/podman run \ --rm \ --rmi \ - --name="pihole_${cfg.hostConfig.user}" \ + --name="${cfg.hostConfig.containerName}" \ ${ if cfg.hostConfig.persistVolumes then '' -v ${cfg.hostConfig.volumesPath}/etc-pihole:/etc/pihole \ @@ -332,6 +340,9 @@ in rec { } \ docker-archive:${piholeFlake.packages.${pkgs.system}.piholeImage} ''; + ExecStop = '' + ${pkgs.podman}/bin/podman stop ${cfg.hostConfig.containerName} + ''; #TODO check that user can control podman & has subuidmap/subgidmap set User = "${cfg.hostConfig.user}"; };