Subject: Re: [PATCH] deploy: Support --target and --system.

From: Sergey Trofimov <[email-masked]>
Date: Thu, 20 Mar 2025 14:43:20 +0100

Hi Maxim,

Maxim Cournoyer <[email-masked]> writes:

> Hi Sergey, Roman,
>
> Sergey Trofimov <[email-masked]> writes:
>
> [...]
>
>>>> I don't see a "system" field in the machine or operating system
>>>> record. So I'm not sure if we have a way to infer that yet.
>>>>
>>>> Would it make sense to add such a field and chose the target
>>>> architecture per machine?
>>>>
>>
>> This totally makes sense to me and is the correct way. However I wonder
>> if both the `system` and the `target` fields should be added, so that
>> the user could choose either native or cross build.
>
> We already have platform-system->target and platform-target->system, so
> I assume having one or the other could be enough?.  Looking at
> machine-ssh-configuration, I also see we already have a 'system' field.
>
>
> Perhaps 'guix deploy' could have a '--cross-build' option, or the record
> could have a 'cross-build?' field, or both, with the CLI taking
> precedence over the later, and the target type would be inferred from
> the system via platform-system->target?
>

Consider such case:

deployer = x86_64, (aarch64 via binfmt)
builder1 = x86_64, (aarch64 via binfmt)
builder2 = aarch64, (x86_64 via binfmt)
remote1 = x86_64
remote2 = aarch64

The user intends to run `guix deploy all-remotes.scm` on `deployer` to
deploy both `remote1` and `remote2`.

There are many ways how to build the derivations - deployer and builders
could all build native/emulated/cross, remotes could build for
themselves (`build-locally?` to `#f`). I am not sure to what extent this
should be configurable, however here are a couple things I'd change:
- add `platform` to `machine` record
- remove `system` from `machine-ssh-configuration`
- remove `build-locally?` from `machine-ssh-configuration`
- add `build-options` to `machine`
  - `build-host` = `local|offload|remote`
  - `build-type` = `native|cross`

Additionally `guix-daemon` should know all the systems the host
supports. Currently it knows only the native one (`--system` parameter).

>
> In my experience, assuming a powerful x86_64 workstation,
> cross-compilation > native-compilation (on lower spec ARM machine) >
> emulated native compilation (QEMU).
>

I'm on a beaten thinkpad (i5-3320m) and it takes ages to compile the
cross toolchain. It turned out that `(build-locally? #f)` is the fastest
way to deploy an ARM server.