From 2e16b8052b59ab5102ee5b604ff79da51b9bbde2 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Sat, 13 May 2023 17:24:13 -0400 Subject: [PATCH] First pass at oracles automation --- machines/oracles/automation.nix | 31 ++++++++++++++++++++++++++++++ machines/oracles/configuration.nix | 3 +-- scripts/gitea/update-repo.sh | 22 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 machines/oracles/automation.nix create mode 100755 scripts/gitea/update-repo.sh diff --git a/machines/oracles/automation.nix b/machines/oracles/automation.nix new file mode 100644 index 0000000..01b3d4d --- /dev/null +++ b/machines/oracles/automation.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, inputs, ... }: +let + repo-updater = pkgs.writeShellScriptBin "repo-updater" + (builtins.readFile ../../scripts/gitea/update-repo.sh); +in { + # Setup hosts for gitea automation + networking.hosts = { "100.99.69.14" = [ "git.stranger.systems" ]; }; + # Automate updating rust utility flake + systemd.services."rust-util-update" = { + environment = { + XDG_RUNTIME_DIR = "/tmp"; + HOME = "/home/nathan"; + }; + path = with pkgs; [ + git + inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.nurl + jq + curl + openssh + bash + ]; + script = '' + env + {repo-updater}/bin/repo-updater gitea@git.stranger.systems:nix/Rust.git trunk + ''; + serviceConfig = { + Type = "oneshot"; + User = "nathan"; + }; + }; +} diff --git a/machines/oracles/configuration.nix b/machines/oracles/configuration.nix index 9642772..c771522 100644 --- a/machines/oracles/configuration.nix +++ b/machines/oracles/configuration.nix @@ -1,6 +1,7 @@ { config, lib, pkgs, inputs, ... }: { + imports = [ ./automation.nix ]; # Sops setup for this machine sops.secrets = { "borg-ssh-key" = { @@ -148,6 +149,4 @@ locations."/" = { proxyPass = "http://localhost:8091"; }; }; - # Setup hosts for gitea automation - networking.hosts = { "100.99.69.14" = [ "git.stranger.systems" ]; }; } diff --git a/scripts/gitea/update-repo.sh b/scripts/gitea/update-repo.sh new file mode 100755 index 0000000..3a77ff1 --- /dev/null +++ b/scripts/gitea/update-repo.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -eou pipefail + +TEMP_DIR=$(mktemp -d "repo-updater.XXXX" -p $XDG_RUNTIME_DIR) +pushd $TEMP_DIR + +git clone "$1" repo +pushd repo +git switch $2 + +./update.sh + +git add -A +if git commit -m "Update flake/dependencies"; then + git push -u origin $2 +else + echo "No changes made" +fi + +popd +popd +rm -rf $TEMP_DIR