Skip to content

Instantly share code, notes, and snippets.

@Sorixelle
Created December 29, 2023 00:40
Show Gist options
  • Save Sorixelle/0f416db615ba7b4fea45b0bda04e3195 to your computer and use it in GitHub Desktop.
Save Sorixelle/0f416db615ba7b4fea45b0bda04e3195 to your computer and use it in GitHub Desktop.
#! /usr/bin/env nix-shell
#! nix-shell -i fish -p fish
function show_help
echo "deploy - Simple nixos-rebuild wrapper for deploying remote machines"
echo ""
echo "Usage: ./deploy [-h] [-s ssh_server] hostname [rebuild_args]"
echo "Flags:"
echo " -h/--help: Show this message"
echo " -s/--ssh: The SSH address to deploy to. Defaults to the expression name if not supplied"
echo " "
echo "Examples:"
echo " Deploy to a machine called \"foo\":"
echo " ./deploy foo"
echo ""
echo " Deploy the \"foo\" configuration to a particular IP address:"
echo " ./deploy -a 10.0.2.123 foo"
echo ""
echo " Run \"nixos-rebuild -L test\" on \"foo\":"
echo " ./deploy foo -L test"
exit
end
argparse --name=deploy -i 'h/help' 's/ssh=' -- $argv
or return
if [ -n "$_flag_h" ]
show_help
end
if [ -n "$_flag_s" ]
set host $_flag_s
else
set host $argv[1]
end
if [ -z "$argv[1]" ]
echo "deploy: machine name must be specified"
exit 1
end
if [ -n "$argv[2..]" ]
set cmd $argv[2..]
else
set cmd "switch"
end
NIX_SSHOPTS="-t" nixos-rebuild -L --fast --use-remote-sudo --target-host root@$host --flake .#$argv[1] $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment