System/machines/oracles/automation.nix

86 lines
2.4 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, inputs, ... }:
let
repo-updater = pkgs.writeShellScriptBin "repo-updater"
(builtins.readFile ../../scripts/gitea/update-repo.sh);
environment = {
2023-05-21 15:09:52 -04:00
XDG_RUNTIME_DIR = "/tmp/strangerbot";
HOME = "/home/strangerbot";
2023-05-15 08:07:43 -04:00
NIX_PATH =
"nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels";
2023-05-15 08:12:18 -04:00
XDG_CONFIG_DIRS =
"/etc/profiles/per-user/strangerbot/etc/xdg:/nix/var/nix/profiles/default/etc/xdg:/run/current-system/sw/etc/xdg";
XDG_CONFIG_HOME = "/home/strangerbot/.config";
};
path = with pkgs; [
git
inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.nurl
jq
curl
openssh
bash
nix
2023-05-14 19:31:14 -04:00
nix-prefetch
];
2023-05-15 22:36:03 -04:00
update-flake = { name, repo, schedule, branch ? "trunk" }: {
systemd.services."update-flake-${name}" = {
inherit environment;
inherit path;
script = ''
env
${repo-updater}/bin/repo-updater ${repo} ${branch}
'';
serviceConfig = {
Type = "oneshot";
User = "strangerbot";
2023-05-15 22:36:03 -04:00
Group = "users";
};
2023-05-14 19:31:14 -04:00
};
2023-05-15 22:36:03 -04:00
systemd.timers."update-flake-${name}" = {
wantedBy = [ "timers.target" ];
partOf = [ "update-flake-${name}.service" ];
timerConfig = {
OnCalendar = schedule;
Unit = "update-flake-${name}.service";
};
2023-05-14 19:31:14 -04:00
};
};
2023-05-15 22:36:03 -04:00
in lib.mkMerge [
{ # Setup hosts for gitea automation
networking.hosts = { "100.99.69.14" = [ "git.stranger.systems" ]; };
2023-05-15 23:09:55 -04:00
# Setup the bot user
users.users."strangerbot" = {
home = "/home/strangerbot";
description = "Stranger Bot";
isNormalUser = true;
};
home-manager.users."strangerbot" = {
programs.git = {
userName = "Stranger Bot";
userEmail = "bot@stranger.systems";
extraConfig = {
commit.gpgsign = true;
gpg.format = "ssh";
user.signingkey = "~/.ssh/id_ed25519.pub";
};
};
};
2023-05-15 22:36:03 -04:00
}
(update-flake {
name = "system";
repo = "gitea@git.stranger.systems:nix/System.git";
2023-06-08 17:01:17 -04:00
schedule = "Sun, Wed 23:00";
2023-05-15 22:36:03 -04:00
})
(update-flake {
name = "rust-util";
repo = "gitea@git.stranger.systems:nix/Rust.git";
2023-06-08 17:01:17 -04:00
schedule = "Sat, Wed, 4:00";
2023-05-15 22:36:03 -04:00
})
(update-flake {
name = "java";
repo = "gitea@git.stranger.systems:nix/java.git";
branch = "master";
schedule = "6:00";
})
]