diff --git a/hosts/nix-cache01/default.nix b/hosts/nix-cache01/default.nix index 0167962..d57d450 100644 --- a/hosts/nix-cache01/default.nix +++ b/hosts/nix-cache01/default.nix @@ -2,5 +2,6 @@ { imports = [ ./configuration.nix + ../../services/nix-cache ]; } diff --git a/services/monitoring/prometheus.nix b/services/monitoring/prometheus.nix index bd4e8a4..25697b0 100644 --- a/services/monitoring/prometheus.nix +++ b/services/monitoring/prometheus.nix @@ -138,6 +138,7 @@ "ns2.home.2rjus.net:9100" "http-proxy.home.2rjus.net:9100" "ha1.home.2rjus.net:9100" + "nix-cache01.home.2rjus.net:9100" ]; } ]; diff --git a/services/nix-cache/build-flakes.nix b/services/nix-cache/build-flakes.nix new file mode 100644 index 0000000..155bc35 --- /dev/null +++ b/services/nix-cache/build-flakes.nix @@ -0,0 +1,42 @@ +{ pkgs, ... }: +let + build-flake-script = pkgs.writeShellApplication { + name = "build-flake-script"; + runtimeInputs = with pkgs; [ + git + nix + nixos-rebuild + jq + ]; + text = '' + cd /root/nixos-servers + git pull + echo "Starting nixos-servers builds" + for host in $(nix flake show --json| jq -r '.nixosConfigurations | keys[]'); do + echo "Building $host" + nixos-rebuild --verbose -L --flake ".#$host" build + done + echo "All nixos-servers builds complete" + + echo "Building gunter" + cd /root/nixos + git pull + nixos-rebuild --verbose -L --flake ".#gunter" build + ''; + }; +in +{ + systemd.services."build-flakes" = { + serviceConfig = { + Type = "oneshot"; + ExecStart = "${build-flake-script}/bin/build-flake-script"; + }; + }; + systemd.timers."build-flakes" = { + enable = true; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "Sun 06:00:00"; + }; + }; +} diff --git a/services/nix-cache/default.nix b/services/nix-cache/default.nix new file mode 100644 index 0000000..ea56849 --- /dev/null +++ b/services/nix-cache/default.nix @@ -0,0 +1,6 @@ +{ ... }: +{ + imports = [ + ./build-flakes.nix + ]; +}