[pve-devel] [PATCH container] setup: Fix architecture detection for NixOS containers

Fiona Ebner f.ebner at proxmox.com
Mon Aug 21 14:50:28 CEST 2023


Am 28.02.23 um 11:59 schrieb Christoph Heiss:
> diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
> index 891231f..4346c5e 100644
> --- a/src/PVE/LXC/Setup.pm
> +++ b/src/PVE/LXC/Setup.pm
> @@ -131,6 +131,20 @@ sub new {
>  	$plugin->{rootgid} = $rootgid;
>      }
>  
> +    # if arch is unset, we try to autodetect it
> +    if (!defined($conf->{arch})) {
> +	my $arch = eval { $self->protected_call(sub { $plugin->detect_architecture() }) };
> +

The error from the eval should be logged here.

> +	if (!defined($arch)) {
> +	    $arch = 'amd64';
> +	    print "Falling back to $arch.\nUse `pct set VMID --arch ARCH` to change.\n";
> +	} else {
> +	    print "Detected container architecture: $arch\n";
> +	}
> +

(...)

> diff --git a/src/PVE/LXC/Setup/NixOS.pm b/src/PVE/LXC/Setup/NixOS.pm
> index 845d2d5..4f7b93e 100644
> --- a/src/PVE/LXC/Setup/NixOS.pm
> +++ b/src/PVE/LXC/Setup/NixOS.pm
> @@ -5,6 +5,7 @@ use warnings;
>  
>  use File::Path 'make_path';
>  
> +use PVE::LXC::Setup;

This is a cyclic include, please let us avoid those. We could either use
a new helper module for the detect_architecture() helper or otherwise
move it to pve-guest-common or even pve-common. The detection itself is
pretty generic after all.

An alternative to that would be to just add a function get_elf_fn() to
the plugin interface and change the existing detect_architecture() to
use that.

>  use PVE::LXC::Setup::Base;
>  
>  use base qw(PVE::LXC::Setup::Base);





More information about the pve-devel mailing list