From d582d3f352f87d4831aa82398249c6fb6d410cd4 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Sun, 4 Apr 2021 19:35:38 +0100 Subject: [PATCH] ops/nixos/lib: inline latest_system_closure.sh I can't be bothered to make it a proper script, and I also don't really want to rely on invoking nix-shell at runtime (I'd rather have all the needed tools in the system closure). --- ops/nixos/lib/latest_system_closure.sh | 11 ----------- ops/nixos/lib/switch-prebuilt.nix | 9 +++++++-- 2 files changed, 7 insertions(+), 13 deletions(-) delete mode 100755 ops/nixos/lib/latest_system_closure.sh diff --git a/ops/nixos/lib/latest_system_closure.sh b/ops/nixos/lib/latest_system_closure.sh deleted file mode 100755 index 52c4abea69..0000000000 --- a/ops/nixos/lib/latest_system_closure.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p bash jq curl unzip - -set -euo pipefail - -tmpdir="$(mktemp -d)" -trap '{ rm -rf -- "$tmpdir"; }' EXIT - -curl -so "$tmpdir/archive.zip" 'https://hg.lukegb.com/api/v4/projects/lukegb%2Fdepot/jobs/artifacts/branch%2Fdefault/download?job=nixCache' -unzip -d "$tmpdir" -q -o "$tmpdir/archive.zip" -jq -r ".\"$(hostname)\"" "$tmpdir/systems.json" diff --git a/ops/nixos/lib/switch-prebuilt.nix b/ops/nixos/lib/switch-prebuilt.nix index e4e21f3b78..8e4620fdb2 100644 --- a/ops/nixos/lib/switch-prebuilt.nix +++ b/ops/nixos/lib/switch-prebuilt.nix @@ -11,7 +11,12 @@ pkgs.writeShellScriptBin "switch-prebuilt" '' system="''${1}" if [[ "$system" == "latest" ]]; then - system="$(${./latest_system_closure.sh})" + tmpdir="$(mktemp -d)" + trap '{ rm -rf -- "$tmpdir"; }' EXIT + + ${pkgs.curl}/bin/curl -so "$tmpdir/archive.zip" 'https://hg.lukegb.com/api/v4/projects/lukegb%2Fdepot/jobs/artifacts/branch%2Fdefault/download?job=nixCache' + ${pkgs.unzip}/bin/unzip -d "$tmpdir" -q -o "$tmpdir/archive.zip" + system="$(${pkgs.jq}/bin/jq -r ".\"$(hostname)\"" "$tmpdir/systems.json")" fi if [[ ! -e "$system" ]]; then @@ -23,7 +28,7 @@ pkgs.writeShellScriptBin "switch-prebuilt" '' # The next phase requires sudo, but it's harmless to run the preceding commands twice. if [[ $EUID -ne 0 ]]; then - exec sudo "$0" "$@" + exec sudo "$0" "$system" fi nix-env -p /nix/var/nix/profiles/system --set "$system"