diff --git a/hosts/bekkalokk/services/website/fetch-gallery.nix b/hosts/bekkalokk/services/website/fetch-gallery.nix index 0271971..be608a5 100644 --- a/hosts/bekkalokk/services/website/fetch-gallery.nix +++ b/hosts/bekkalokk/services/website/fetch-gallery.nix @@ -1,5 +1,43 @@ { pkgs, lib, config, ... }: -{ +let + galleryDir = config.services.pvv-nettsiden.settings.GALLERY.DIR; + transferDir = "${config.services.pvv-nettsiden.settings.GALLERY.DIR}-transfer"; +in { + users.users.${config.services.pvv-nettsiden.user} = { + useDefaultShell = true; + openssh.authorizedKeys.keys = [ + ''command="${pkgs.rrsync}/bin/rrsync -wo ${transferDir}",restrict,no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIjHhC2dikhWs/gG+m7qP1eSohWzTehn4ToNzDSOImyR gallery-publish'' + ]; + }; + + systemd.paths.pvv-nettsiden-gallery-update = { + wantedBy = [ "multi-user.target" ]; + pathConfig = { + PathChanged = "${transferDir}/gallery.tar.gz"; + Unit = "pvv-nettsiden-gallery-update.service"; + MakeDirectory = true; + }; + }; + + systemd.services.pvv-nettsiden-gallery-update = { + path = with pkgs; [ gnutar gzip ]; + + script = '' + tar ${lib.cli.toGNUCommandLineShell {} { + extract = true; + file = "${transferDir}/gallery.tar.gz"; + directory = "."; + }} + + # Delete files and directories that exists in the gallery that don't exist in the tarball + rm -f $(uniq -u <(sort <(find . -depth) <(tar -tf ${transferDir}/gallery.tar.gz | sed 's|/$||' ))) + ''; + + serviceConfig = { + WorkingDirectory = galleryDir; + User = config.services.pvv-nettsiden.user; + Group = config.services.pvv-nettsiden.group; + }; + }; } -