refactor(scripts): move rebuild to nix file
This commit is contained in:
parent
73c0ebb467
commit
f082ed8ac0
2 changed files with 52 additions and 48 deletions
|
@ -9,7 +9,58 @@
|
|||
];
|
||||
} (builtins.readFile ./git-extract.py))
|
||||
|
||||
(pkgs.writeShellScriptBin "rebuild" (builtins.readFile ./rebuild.sh))
|
||||
(pkgs.writeShellScriptBin "rebuild" # sh
|
||||
''
|
||||
rebuild_remote() {
|
||||
git add .
|
||||
hostname=$1
|
||||
builder="nemesis"
|
||||
if [[ "''${hostname}" == "''${builder}" ]]; then
|
||||
nh os switch .
|
||||
else
|
||||
nixos-rebuild switch \
|
||||
--flake .#"''${hostname}" \
|
||||
--target-host "$(whoami)"@"''${hostname}" \
|
||||
--build-host "''${builder}" \
|
||||
--use-remote-sudo
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
if [[ $# -gt 1 ]]; then
|
||||
echo "Only one argument is allowed. Pass in a hostname or all."
|
||||
exit 1
|
||||
elif [[ $# -lt 1 ]]; then
|
||||
rebuild_remote "$HOSTNAME"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
all)
|
||||
# Create a list of hostnames to rebuild
|
||||
hosts=("nemesis" "apollo")
|
||||
|
||||
# Use parallel to rebuild each host
|
||||
, parallel rebuild ::: "''${hosts[@]}"
|
||||
|
||||
# Check the exit code of parallel
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "One or more rebuilds failed."
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
rebuild_remote "$1"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
||||
''
|
||||
)
|
||||
(pkgs.writeShellScriptBin "byebye" (builtins.readFile ./byebye.sh))
|
||||
(pkgs.writeShellScriptBin "deploy" (builtins.readFile ./deploy.sh))
|
||||
];
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
rebuild_remote() {
|
||||
hostname=$1
|
||||
builder="nemesis"
|
||||
if [[ "${hostname}" == "${builder}" ]]; then
|
||||
nh os switch .
|
||||
else
|
||||
nixos-rebuild switch --flake .#"${hostname}" --target-host "$(whoami)"@"${hostname}" --build-host "${builder}" --use-remote-sudo
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
if [[ $# -gt 1 ]]; then
|
||||
echo "Only one argument is allowed. Pass in a hostname or all."
|
||||
exit 1
|
||||
elif [[ $# -lt 1 ]]; then
|
||||
rebuild_remote "$HOSTNAME"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git add .
|
||||
|
||||
case "$1" in
|
||||
all)
|
||||
# Create a list of hostnames to rebuild
|
||||
hosts=("nemesis" "apollo")
|
||||
|
||||
# Use parallel to rebuild each host
|
||||
, parallel rebuild ::: "${hosts[@]}"
|
||||
|
||||
# Check the exit code of parallel
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "One or more rebuilds failed."
|
||||
exit 1
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
rebuild_remote "$1"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
Loading…
Add table
Add a link
Reference in a new issue