if test (count $argv) -ne 1 echo "usage: deploy-to " >&2 return 2 end set host $argv[1] git rev-parse --show-toplevel >/dev/null 2>&1 or begin echo "deploy-to: run this from a git checkout" >&2 return 2 end set repository_root (git rev-parse --show-toplevel) or return $status set untracked_nix_files (git -C $repository_root ls-files --others --exclude-standard -- '*.nix' flake.nix flake.lock) if test (count $untracked_nix_files) -gt 0 echo "deploy-to: warning: untracked Nix files are not part of Git flake evaluation" >&2 printf ' %s\n' $untracked_nix_files >&2 end set installable "$repository_root#nixosConfigurations.$host.config.system.build.toplevel" echo "deploy-to: building $installable" >&2 set system_path (nix build --no-link --print-out-paths $installable) or begin echo "deploy-to: build failed for $host" >&2 return $status end if test (count $system_path) -ne 1 echo "deploy-to: expected one build output, got "(count $system_path) >&2 return 1 end echo "deploy-to: copying $system_path to $host" >&2 nix copy --to ssh://$host $system_path or begin echo "deploy-to: copy failed for $host" >&2 return $status end echo "deploy-to: activating $system_path on $host" >&2 ssh -t $host sudo "$system_path/bin/switch-to-configuration" switch or begin echo "deploy-to: activation failed for $host" >&2 return $status end