{ config, pkgs, lib, secrets, ... }: { systemd.services = { "auto-redeploy" = { wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; serviceConfig = { ExecStart = '' ${pkgs.curl}/bin/curl -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "System started redeploy."}' ${secrets.webhooks.discord.deploy} cd /Spacebar-Open-Architecture #store current commit hash currentCommit=$(git rev-parse HEAD) git fetch --all #check if there are any new commits if [ $(git rev-parse HEAD) = $(git rev-parse @{u}) ]; then echo "Already up-to-date" exit 0 fi #pull new commits git pull #send commit log to discord ${pkgs.curl}/bin/curl -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "```$(git log --pretty=format:"%h - %s" $currentCommit..HEAD)```"}' ${secrets.webhooks.discord.deploy} #call ./update.sh and store output (including stderr) in a file ./update.sh 2>&1 | tee /tmp/update.log #send the output to discord as a file ${pkgs.curl}/bin/curl -F "file=@/tmp/update.log" -F "filename=update.log" -F "content=System finished redeploy." -H "Content-Type: multipart/form-data" ${secrets.webhooks.discord.deploy} ''; Restart = "always"; RestartSec = 60; User = "root"; }; }; }; }