From e711bc69a1748668620bd907159789e50507d793 Mon Sep 17 00:00:00 2001 From: clerie Date: Sun, 5 Nov 2023 17:24:27 +0100 Subject: [PATCH] pkgs/nixfiles: add script for installing the last system successfully built by hydra --- flake.nix | 1 + .../nixfiles-system-sync-to-hydra.nix | 11 +++++++++++ .../nixfiles/nixfiles-system-sync-to-hydra.sh | 19 +++++++++++++++++++ pkgs/overlay.nix | 1 + 4 files changed, 32 insertions(+) create mode 100644 pkgs/nixfiles/nixfiles-system-sync-to-hydra.nix create mode 100755 pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh diff --git a/flake.nix b/flake.nix index 65e05d0..b01750e 100644 --- a/flake.nix +++ b/flake.nix @@ -109,6 +109,7 @@ nixfiles-auto-install nixfiles-generate-backup-secrets nixfiles-generate-config + nixfiles-system-sync-to-hydra nixfiles-updated-inputs nixfiles-update-ssh-host-keys nixos-firewall-tool diff --git a/pkgs/nixfiles/nixfiles-system-sync-to-hydra.nix b/pkgs/nixfiles/nixfiles-system-sync-to-hydra.nix new file mode 100644 index 0000000..41c32d2 --- /dev/null +++ b/pkgs/nixfiles/nixfiles-system-sync-to-hydra.nix @@ -0,0 +1,11 @@ +{ pkgs, ... }: + +pkgs.writeShellApplication { + name = "nixfiles-system-sync-to-hydra"; + text = builtins.readFile ./nixfiles-system-sync-to-hydra.sh; + runtimeInputs = with pkgs; [ + curl + jq + nix + ]; +} diff --git a/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh b/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh new file mode 100755 index 0000000..c6f83a0 --- /dev/null +++ b/pkgs/nixfiles/nixfiles-system-sync-to-hydra.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -euo pipefail + +HYDRA_JOB_URL="https://hydra.clerie.de/job/nixfiles/nixfiles/nixosConfigurations.$(hostname)/latest-finished" + +echo "Fetching job output from ${HYDRA_JOB_URL}" +STORE_PATH="$(curl --fail -s -L -H "Accept: application/json" "${HYDRA_JOB_URL}" | jq -r ".buildoutputs.out.path")" + +echo "Download ${STORE_PATH}" +nix copy --from "https://nix-cache.clerie.de" "${STORE_PATH}" + +echo "Add to system profile" +nix-env -p "/nix/var/nix/profiles/system" --set "${STORE_PATH}" + +echo "Activate system" +/nix/var/nix/profiles/system/bin/switch-to-configuration switch + +echo "Finished system upgrade" diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix index 5aa6a7d..2d5ffdf 100644 --- a/pkgs/overlay.nix +++ b/pkgs/overlay.nix @@ -6,6 +6,7 @@ self: super: { nixfiles-auto-install = self.callPackage ./nixfiles/nixfiles-auto-install.nix {}; nixfiles-generate-backup-secrets = self.callPackage ./nixfiles/nixfiles-generate-backup-secrets.nix {}; nixfiles-generate-config = self.callPackage ./nixfiles/nixfiles-generate-config.nix {}; + nixfiles-system-sync-to-hydra = self.callPackage ./nixfiles/nixfiles-system-sync-to-hydra.nix {}; nixfiles-updated-inputs = self.callPackage ./nixfiles/nixfiles-updated-inputs.nix {}; nixfiles-update-ssh-host-keys = self.callPackage ./nixfiles/nixfiles-update-ssh-host-keys.nix {}; nixos-firewall-tool = self.callPackage ./nixos-firewall-tool {};