1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-30 22:21:02 +01:00

podman: added volume, image, and build quadlets (#6137)

Added support for build, image, and volume quadlets
Resolved test failures due to podman 5.3.0 upgrade
Replaced several instances of pkgs.podman with services.podman.package
This commit is contained in:
bamhm182 2025-03-10 00:02:05 -04:00 committed by GitHub
parent f8bb0ba6de
commit ce9cb2496c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 1000 additions and 54 deletions

View file

@ -18,6 +18,7 @@
local manifestFile="${config.xdg.configHome}/podman/$2"
local extraListCommands="''${3:-}"
[[ $resourceType = "container" ]] && extraListCommands+=" -a"
[[ $resourceType = "volume" ]] && extraListCommands+=" --filter label=nix.home-manager.preserve=false"
[ ! -f "$manifestFile" ] && VERBOSE_ENABLED && echo "Manifest does not exist: $manifestFile" && return 0
@ -27,6 +28,7 @@
formatString="{{.Name}}"
[[ $resourceType = "container" ]] && formatString="{{.Names}}"
[[ $resourceType = "image" ]] && formatString="{{.Repository}}"
local listOutput=$(${config.services.podman.package}/bin/podman $resourceType ls $extraListCommands --filter 'label=nix.home-manager.managed=true' --format "$formatString")
@ -36,12 +38,12 @@
VERBOSE_ENABLED && echo "No ''${resourceType}s available to process." || true
else
for resource in "''${podmanResources[@]}"; do
if ! isResourceInManifest "$resource"; then
removeResource "$resourceType" "$resource"
else
VERBOSE_ENABLED && echo "Keeping managed $resourceType: $resource" || true
fi
done
if ! isResourceInManifest "$resource"; then
removeResource "$resourceType" "$resource"
else
VERBOSE_ENABLED && echo "Keeping managed $resourceType: $resource" || true
fi
done
fi
}
@ -69,19 +71,20 @@
commands=()
case "$resourceType" in
"container")
commands+="${config.services.podman.package}/bin/podman $resourceType stop $resource"
commands+="${config.services.podman.package}/bin/podman $resourceType rm -f $resource"
commands+=("${config.services.podman.package}/bin/podman $resourceType stop $resource")
commands+=("${config.services.podman.package}/bin/podman $resourceType rm -f $resource")
;;
"network")
commands+="${config.services.podman.package}/bin/podman $resourceType rm $resource"
"image" | "network" | "volume")
commands+=("${config.services.podman.package}/bin/podman $resourceType rm $resource")
;;
esac
for command in "''${commands[@]}"; do
command=$(echo $command | tr -d ';&|`')
DRYRUN_ENABLED && echo "Would run: $command" && continue || true
VERBOSE_ENABLED && echo "Running: $command" || true
if [[ "$(eval "$command")" != "$resource" ]]; then
if [[ "$(eval "$command")" != *"$resource" ]]; then
echo -e "\tCommand failed: ''${command}"
[ "$resourceType" == "image" ] && resourceType="ancestor"
usedByContainers=$(${config.services.podman.package}/bin/podman container ls -a --filter "$resourceType=$resource" --format "{{.Names}}")
echo -e "\t$resource in use by containers: $usedByContainers"
fi
@ -92,7 +95,7 @@
[[ "$@" == *"--verbose"* ]] && VERBOSE="true"
[[ "$@" == *"--dry-run"* ]] && DRY_RUN="true"
for type in "container" "network"; do
for type in "container" "image" "network" "volume"; do
cleanup "$type" "''${type}s.manifest"
done
'';