From 8ed767242ad201aa2a77b57d021391f1a04f2a30 Mon Sep 17 00:00:00 2001 From: vkcku Date: Mon, 1 Jun 2026 20:04:02 +0530 Subject: infra: add deploy script monorepo-revid: 84b860704659f6c878f887f7e0b6ce61dad9f907 --- infra/deploy.nix | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 infra/deploy.nix diff --git a/infra/deploy.nix b/infra/deploy.nix new file mode 100644 index 0000000..c828008 --- /dev/null +++ b/infra/deploy.nix @@ -0,0 +1,62 @@ +{ + perSystem = + { lib, pkgs, ... }: + { + apps.infra-deploy = + let + hosts = builtins.attrNames ( + lib.attrsets.filterAttrs (_: type: type == "directory") (builtins.readDir ./hosts) + ); + + bin = pkgs.writeShellApplication { + name = "deploy"; + runtimeInputs = [ + # keep-sorted start + pkgs.fzf + pkgs.git + pkgs.inetutils + pkgs.nixos-rebuild + # keep-sorted end + ]; + text = '' + selected=("$@") + + if [ "''${#selected[@]}" -eq 0 ]; then + readarray -t selected < <(printf '%s\n' ${lib.escapeShellArgs hosts} | fzf --multi) + fi + + if [ "''${#selected[@]}" -eq 0 ]; then + echo "error: no host selected" >&2 + exit 1 + fi + + if [ "''${#selected[@]}" -eq 1 ] && [ "''${selected[0]}" = "all" ]; then + selected=(${lib.escapeShellArgs hosts}) + fi + + rootdir="$(git rev-parse --show-toplevel)" + + for host in "''${selected[@]}"; do + target=() + if [ "$host" != "$(hostname)" ]; then + target=(--target-host "deploy@$host") + fi + + echo "info: deploying $host" + nixos-rebuild switch \ + --no-reexec \ + --use-substitutes \ + --sudo \ + --flake "$rootdir#$host" \ + "''${target[@]}" + done + ''; + }; + in + { + type = "app"; + program = "${bin}/bin/deploy"; + meta.description = "deploy the nixos configurations to the given hosts"; + }; + }; +} -- cgit v1.3.1