System/machines/oracles/automation.nix

69 lines
1.9 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 = {
XDG_RUNTIME_DIR = "/tmp";
HOME = "/home/nathan";
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 =
"/home/nathan/.nix-profile/etc/xdg:/etc/profiles/per-user/nathan/etc/xdg:/nix/var/nix/profiles/default/etc/xdg:/run/current-system/sw/etc/xdg";
XDG_CONFIG_HOME = "/home/nathan/.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 = "nathan";
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" ]; };
}
(update-flake {
name = "system";
repo = "gitea@git.stranger.systems:nix/System.git";
schedule = "Mon, 4:00";
})
(update-flake {
name = "rust-util";
repo = "gitea@git.stranger.systems:nix/Rust.git";
schedule = "Mon, 8:00";
})
(update-flake {
name = "java";
repo = "gitea@git.stranger.systems:nix/java.git";
branch = "master";
schedule = "6:00";
})
]