nix-community / nixos-anywhere

install nixos everywhere via ssh [maintainer=@numtide]
https://nix-community.github.io/nixos-anywhere/
MIT License
1.49k stars 106 forks source link

Compatibility for "cross-architecture" installation #18

Open TheSirC opened 1 year ago

TheSirC commented 1 year ago

Thank you a lot for this !

Is it possible to use this method to remote install Raspberry Pi (and generally different architectures than the client connecting to ssh host to install nixos on) from a x86_64 system?

phaer commented 1 year ago

I think there's nothings which should stop this from working on a Raspberry Pi in theory, but I don't believe it has been tried before.

@Mic92 Just exposed aarch64 for the kexec images https://github.com/nix-community/nixos-images/pull/50/files, but this flake might need adaptions.

Mic92 commented 1 year ago

I mainly need time to prepare ci for aarch64...

Mic92 commented 1 year ago

Btw if you possess some other arm64 machine that can act as a remote builder, than you can already deploy nixos to a new machine as described here: https://github.com/numtide/nixos-remote#using-your-own-kexec-image

This is what I have done for the nix-community oracle builder: https://github.com/nix-community/infra/blob/6e89a59895ef690e2918a5dabbf92241e7464c19/build04/configuration.nix#L42

arjan-s commented 1 year ago

Hi, has there been progress on this? I was hoping to use it to install a new aarch64 machine.

I used the aarch64 kexec installer using this command:

nix run github:numtide/nixos-anywhere -- <hostname> --flake .#<hostname> --kexec "$(nix build --print-out-paths github:nix-community/nixos-images#packages.aarch64-linux.kexec-installer-nixos-unstable)/nixos-kexec-installer-aarch64-linux.tar.gz"

but encountered the following error:

error: a 'aarch64-linux' with features {} is required to build '/nix/store/pr53dvbv21q1ajp3fhrk5zy1d5qpy8gj-append-initrd-secrets.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, kvm, nixos-test}

curl: (3) URL using bad/illegal format or missing URL

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
phaer commented 1 year ago

Iiuc you'd still need an aarch64 (remote) builder for the nixos-anywhere parts, even if you use a pre-built aarch64 installer image.

We still don't have CI for aarch64 yet, maybe @Mic92 has plans for it? :)

Mic92 commented 1 year ago

Some progress has been made on aarch64 CI: https://github.com/nix-community/nixos-images/pull/87

arjan-s commented 1 year ago

Actually, it worked perfectly after adding the following line to my laptop's config:

boot.binfmt.emulatedSystems = [ "aarch64-linux" ];

I used the nixos-anywhere command I listed in my previous comment to successfully install an Oracle (free tier) aarch64 host. This line configured my laptop to 'understand' aarch64 building through qemu.

nixos-discourse commented 7 months ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/cross-build-x86-64-ami-on-aarch64-using-nixos-generators/39098/2

genebean commented 7 months ago

I am also getting the

error: a 'aarch64-linux' with features {} is required to 
build '/nix/store/nbykp926jwdpnp6aj2cbkygkwv16256m-default-conf.json.drv', 
but I am a 'x86_64-darwin' with features {benchmark, big-parallel, nixos-test}

when I run this:

nix run github:nix-community/nixos-anywhere -- \
--flake .#hetznix01 -i ~/.ssh/id_ed25519 \
--build-on-remote root@<redacted>

(line breaks added to both things above to make them easier to read)

The thing that has me confused, and may make this a different issue, is I am passing --build-on-remote which, I would think, would avoid the issue of my laptop not being the right architecture. Anyone here have any thoughts on either what I am doing wrong or how to work around it? I do have an x86_64-linux laptop running NixOS I could deploy from if needed.

Mic92 commented 7 months ago

For this feature to work, your own local user needs to be a trusted nix user.

genebean commented 7 months ago

For this feature to work, your own local user needs to be a trusted nix user.

The user is in the list of trusted ones.

The one I tried from a NixOS host is in this one:

https://github.com/genebean/dots/blob/437a34a26dba30cc926a543e21dee053783eb6a5/modules/system/common/all-nixos.nix#L43

When I tried from macOS, it is in this one:

https://github.com/genebean/dots/blob/437a34a26dba30cc926a543e21dee053783eb6a5/modules/system/common/all-darwin.nix#L91