From 5bf0de1d0dfd82246c395e84068fc94d4ee10a3f Mon Sep 17 00:00:00 2001 From: h7x4 Date: Thu, 28 May 2026 03:58:08 +0900 Subject: [PATCH] bekkalokk/website/fetch-gallery: use proper shellscript builder --- .../services/website/fetch-gallery.nix | 81 ++++++++++--------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/hosts/bekkalokk/services/website/fetch-gallery.nix b/hosts/bekkalokk/services/website/fetch-gallery.nix index bd929ec..8886f3d 100644 --- a/hosts/bekkalokk/services/website/fetch-gallery.nix +++ b/hosts/bekkalokk/services/website/fetch-gallery.nix @@ -37,47 +37,56 @@ in { }; systemd.services.pvv-nettsiden-gallery-update = { - path = with pkgs; [ imagemagick gnutar gzip ]; - - script = '' - tar ${lib.cli.toCommandLineShellGNU { } { - extract = true; - file = "${transferDir}/gallery.tar.gz"; - directory = "."; - }} - - # Delete files and directories that exists in the gallery that don't exist in the tarball - filesToRemove=$(uniq -u <(sort <(find . -not -path './.thumbnails*') <(tar -tf '${transferDir}/gallery.tar.gz' | sed 's|/$||'))) - while IFS= read -r fname; do - rm -f "$fname" ||: - rm -f ".thumbnails/$fname.png" ||: - done <<< "$filesToRemove" - - find . -type d -empty -delete - - mkdir -p .thumbnails - images=$(find . -type f -not -path './.thumbnails*') - - while IFS= read -r fname; do - # Skip this file if an up-to-date thumbnail already exists - if [ -f ".thumbnails/$fname.png" ] && \ - [ "$(date -R -r "$fname")" == "$(date -R -r ".thumbnails/$fname.png")" ] - then - continue - fi - - echo "Creating thumbnail for $fname" - mkdir -p "$(dirname ".thumbnails/$fname")" - magick -define jpeg:size=200x200 "$fname" -thumbnail 300 -auto-orient ".thumbnails/$fname.png" ||: - touch -m -d "$(date -R -r "$fname")" ".thumbnails/$fname.png" - done <<< "$images" - ''; - serviceConfig = { WorkingDirectory = galleryDir; User = config.services.pvv-nettsiden.user; Group = config.services.pvv-nettsiden.group; + ExecStart = lib.getExe (pkgs.writeShellApplication { + name = "pvv-nettsiden-gallery-update-exec-start.sh"; + runtimeInputs = with pkgs; [ + coreutils + findutils + gnused + gnutar + gzip + imagemagick + ]; + text = '' + tar ${lib.cli.toCommandLineShellGNU { } { + extract = true; + file = "${transferDir}/gallery.tar.gz"; + directory = "."; + }} + + # Delete files and directories that exists in the gallery that don't exist in the tarball + filesToRemove="$(uniq -u <(sort <(find . -not -path './.thumbnails*') <(tar -tf '${transferDir}/gallery.tar.gz' | sed 's|/$||')))" + while IFS= read -r fname; do + rm -f "$fname" ||: + rm -f ".thumbnails/$fname.png" ||: + done <<< "$filesToRemove" + + find . -type d -empty -delete + + mkdir -p .thumbnails + images="$(find . -type f -not -path './.thumbnails*')" + + while IFS= read -r fname; do + # Skip this file if an up-to-date thumbnail already exists + if [ -f ".thumbnails/$fname.png" ] && \ + [ "$(date -R -r "$fname")" == "$(date -R -r ".thumbnails/$fname.png")" ] + then + continue + fi + + echo "Creating thumbnail for $fname" + mkdir -p "$(dirname ".thumbnails/$fname")" + magick -define jpeg:size=200x200 "$fname" -thumbnail 300 -auto-orient ".thumbnails/$fname.png" ||: + touch -m -d "$(date -R -r "$fname")" ".thumbnails/$fname.png" + done <<< "$images" + ''; + }); + AmbientCapabilities = [ "" ]; CapabilityBoundingSet = [ "" ]; DeviceAllow = [ "" ];