mirror of
https://github.com/nix-community/nixos-anywhere.git
synced 2024-08-16 20:00:36 +03:00
use local eval and copy-closure to the target
This commit is contained in:
parent
4e957c8768
commit
e6788fcd68
50
nixos-remote
50
nixos-remote
@ -65,6 +65,38 @@ timeout_ssh_() {
|
||||
ssh_() {
|
||||
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$ssh_connection" "$@"
|
||||
}
|
||||
nixCopy() {
|
||||
NIX_SSHOPTS='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' nix copy --extra-experimental-features nix-command "$@"
|
||||
}
|
||||
nix_build() {
|
||||
nix \
|
||||
--experimental-features flakes build \
|
||||
--extra-experimental-features nix-command \
|
||||
--no-write-lock-file \
|
||||
--print-out-paths \
|
||||
"$@"
|
||||
}
|
||||
|
||||
nixos_system=""
|
||||
# parse flake nixos-install style syntax, get the system attr
|
||||
if [[ ! -z "${flake+x}" ]]; then
|
||||
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
||||
flake="${BASH_REMATCH[1]}"
|
||||
flakeAttr="${BASH_REMATCH[2]}"
|
||||
fi
|
||||
if [[ -z "$flakeAttr" ]]; then
|
||||
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri."
|
||||
echo "For example, to use the output nixosConfigurations.foo from the flake.nix, append \"#foo\" to the flake-uri."
|
||||
exit 1
|
||||
fi
|
||||
disko_script=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.disko")
|
||||
nixos_system=$(nix_build "${flake}#nixosConfigurations.${flakeAttr}.config.system.build.toplevel")
|
||||
else
|
||||
abort "flake must be set"
|
||||
fi
|
||||
|
||||
# wait for machine to become reachable (possibly forever)
|
||||
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
||||
|
||||
# first check if the remote system is kexec booted
|
||||
if $(ssh_ -- test -e /etc/is_kexec); then
|
||||
@ -109,20 +141,12 @@ SSH
|
||||
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
||||
fi
|
||||
|
||||
nixCopy --to "ssh://$ssh_connection" "$disko_script"
|
||||
ssh_ $disko_script
|
||||
|
||||
nixCopy --to "ssh://$ssh_connection?remote-store=local?root=/mnt" "$nixos_system"
|
||||
ssh_ << SSH
|
||||
set -efux
|
||||
$(declare -p nix_args)
|
||||
nix --extra-experimental-features nix-command --extra-experimental-features flakes \
|
||||
run github:nix-community/disko \
|
||||
--no-write-lock-file -- \
|
||||
--debug -m create "\${nix_args[@]}" --flake "$flake"
|
||||
|
||||
nix --extra-experimental-features nix-command --extra-experimental-features flakes \
|
||||
run github:nix-community/disko \
|
||||
--no-write-lock-file -- \
|
||||
--debug -m mount "\${nix_args[@]}" --flake "$flake"
|
||||
|
||||
nixos-install --flake "$flake"
|
||||
set -efu
|
||||
nixos-install --no-root-passwd --no-channel-copy --system "$nixos_system"
|
||||
reboot
|
||||
SSH
|
||||
|
Loading…
Reference in New Issue
Block a user