diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-04-03 19:26:12 +0200 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-06-05 17:24:37 +0200 |
commit | dcfcf350b74fa731e5ad0ba645bec08264812a8d (patch) | |
tree | 1ac7bcc464f0eef9168b6e84e6305c14ce630dd0 /modules/auto-redeploy.nix | |
parent | Move first webhook to after update check (diff) | |
download | Spacebar-Open-Infrastructure-dcfcf350b74fa731e5ad0ba645bec08264812a8d.tar.xz |
Port update script to service
Diffstat (limited to 'modules/auto-redeploy.nix')
-rw-r--r-- | modules/auto-redeploy.nix | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/modules/auto-redeploy.nix b/modules/auto-redeploy.nix index e3b81fc..ed951c7 100644 --- a/modules/auto-redeploy.nix +++ b/modules/auto-redeploy.nix @@ -12,34 +12,44 @@ }; }; }; + #Emma - Auto-redeploy service systemd.services = { "auto-redeploy" = { #wantedBy = [ "multi-user.target" ]; #after = [ "network.target" ]; + path = with pkgs; [ git curl nix nixos-install-tools nixos-rebuild ]; serviceConfig = { ExecStart = pkgs.writeShellScript "auto-redeploy" '' cd /Spacebar-Open-Architecture #store current commit hash - echo "Current commit: $(${pkgs.git}/bin/git rev-parse HEAD)" - currentCommit=$(${pkgs.git}/bin/git rev-parse HEAD) - ${pkgs.git}/bin/git fetch --all + echo "Current commit: $(git rev-parse HEAD)" + currentCommit=$(git rev-parse HEAD) + git fetch --all #check if there are any new commits echo "Checking for new commits..." - echo "Local: $(${pkgs.git}/bin/git rev-parse HEAD)" - echo "Remote: $(${pkgs.git}/bin/git rev-parse @{u})" - if [ $(${pkgs.git}/bin/git rev-parse HEAD) = $(${pkgs.git}/bin/git rev-parse @{u}) ]; then + echo "Local: $(git rev-parse HEAD)" + echo "Remote: $(git rev-parse @{u})" + if [ $(git rev-parse HEAD) = $(git rev-parse @{u}) ]; then echo "Already up-to-date" exit 0 fi - ${pkgs.curl}/bin/curl -S -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "System started redeploy."}' ${secrets.webhooks.discord.deploy} + curl -S -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "System started redeploy."}' ${secrets.webhooks.discord.deploy} #pull new commits - ${pkgs.git}/bin/git pull + git pull #send commit log to discord - ${pkgs.curl}/bin/curl -S -H "Content-Type: application/json" -d '{"username": "${config.networking.hostName} - redeploy", "content": "```$(git log --pretty=format:"%h - %s" $currentCommit..HEAD)```"}' ${secrets.webhooks.discord.deploy} + curl -S -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 + ( + nix flake update + nixos-generate-config --show-hardware-config > hardware-configuration.nix + git add -f hardware-configuration.nix + nixos-rebuild switch --flake ".#${config.networking.hostName}" -j`nproc` --upgrade-all + git rm --cached hardware-configuration.nix + ) 2>&1 | tee /tmp/update.log #send the output to discord as a file - ${pkgs.curl}/bin/curl -S -F "file=@/tmp/update.log" -F "filename=update.log" -F "content=System finished redeploy." -H "Content-Type: multipart/form-data" ${secrets.webhooks.discord.deploy} + curl -S -F "file=@/tmp/update.log" -F "filename=update.log" -F "content=System finished redeploy." -H "Content-Type: multipart/form-data" ${secrets.webhooks.discord.deploy} + #store current commit in file + echo $(git rev-parse HEAD) > currentCommit ''; #Restart = "always"; #RestartSec = 60; |