From 5fb27f33b3cafa4f203f5a26989c934c2542ebea Mon Sep 17 00:00:00 2001 From: Christopher Bacher Date: Fri, 28 Oct 2022 18:48:49 +0200 Subject: [PATCH] modules(pihole-container): pre-start cleanup old pihole containers If container cleanup fails when the machine halts it is necessary to cleanup the old container before the new one starts or it will fail. --- modules/pihole-container.factory.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/pihole-container.factory.nix b/modules/pihole-container.factory.nix index 84311e9..1de525c 100644 --- a/modules/pihole-container.factory.nix +++ b/modules/pihole-container.factory.nix @@ -347,6 +347,7 @@ in rec { ExecStartPre = mkIf cfg.hostConfig.persistVolumes [ "${pkgs.coreutils}/bin/mkdir -p ${cfg.hostConfig.volumesPath}/etc-pihole" "${pkgs.coreutils}/bin/mkdir -p ${cfg.hostConfig.volumesPath}/etc-dnsmasq.d" + ''${pkgs.podman}/bin/podman rm --ignore "${cfg.hostConfig.containerName}"'' ]; ExecStart = '' @@ -369,12 +370,12 @@ in rec { } \ docker-archive:${piholeFlake.packages.${pkgs.system}.piholeImage} ''; - #TODO check that user can control podman & has subuidmap/subgidmap set + User = "${cfg.hostConfig.user}"; }; postStop = '' - while ${pkgs.podman}/bin/podman container exists ${cfg.hostConfig.containerName}; do + while ${pkgs.podman}/bin/podman container exists "${cfg.hostConfig.containerName}"; do ${pkgs.coreutils-full}/bin/sleep 2; done '';