a73714a93c
This adds a first crack at one idea for a generic, non-user-specific rebuild-system script to ops.nixos.rebuild-system. The idea here is that we enumerate all the nixos systems stored in the monorepo (similarly to what we do for ci-builds right now) then search through them by hostname to find the one matching the hostname of the current system, which is an attempt at a more generic version of tazjin's rebuilder script which does the same thing but with an explicit case block. As a caveat, it feels like there's a slight possibility that this way of finding systems is going to get slow to evaluate - on my system it feels fine but if it grows out of hand it's probably feasible to just bake this into the built script as a dynamically generated case statement. Change-Id: I2e4c5401913b6f4d936ab48ba2f95f96e0e78eb4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/894 Tested-by: BuildkiteCI Reviewed-by: lukegb <lukegb@tvl.fyi>
34 lines
886 B
Nix
34 lines
886 B
Nix
{ depot, ... }:
|
|
|
|
rec {
|
|
chupacabra = import ./machines/chupacabra.nix;
|
|
|
|
rebuilder =
|
|
let
|
|
depotPath = "/home/grfn/code/depot";
|
|
|
|
caseFor = hostname: ''
|
|
${hostname})
|
|
echo "Rebuilding NixOS for //users/glittershark/nixos/${hostname}"
|
|
system=$(nix-build -E '(import ${depotPath} {}).users.glittershark.system.system.${hostname}' --no-out-link)
|
|
;;
|
|
'';
|
|
in depot.third_party.writeShellScriptBin "rebuilder" ''
|
|
set -ue
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "Oh no! Only root is allowed to rebuild the system!" >&2
|
|
exit 1
|
|
fi
|
|
|
|
case $HOSTNAME in
|
|
${caseFor "chupacabra"}
|
|
*)
|
|
echo "$HOSTNAME is not a known NixOS host!" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
nix-env -p /nix/var/nix/profiles/system --set $system
|
|
$system/bin/switch-to-configuration switch
|
|
'';
|
|
}
|