use PVE::LXC::Setup::Gentoo;
use PVE::LXC::Setup::SUSE;
use PVE::LXC::Setup::Ubuntu;
+use PVE::LXC::Setup::NixOS;
+use PVE::LXC::Setup::Unmanaged;
my $plugins = {
alpine => 'PVE::LXC::Setup::Alpine',
gentoo => 'PVE::LXC::Setup::Gentoo',
opensuse => 'PVE::LXC::Setup::SUSE',
ubuntu => 'PVE::LXC::Setup::Ubuntu',
+ nixos => 'PVE::LXC::Setup::NixOS',
+ unmanaged => 'PVE::LXC::Setup::Unmanaged',
};
# a map to allow supporting related distro flavours
return "alpine";
} elsif (-f "$rootdir/etc/gentoo-release") {
return "gentoo";
+ } elsif (-d "$rootdir/nix/store") {
+ return "nixos";
} elsif (-f "$rootdir/etc/os-release") {
die "unable to detect OS distribution\n";
} else {
my $os_release = $self->get_ct_os_release();
if ($conf->{ostype} && $conf->{ostype} eq 'unmanaged') {
- return $self;
+ $type = 'unmanaged';
} elsif (!defined($type)) {
# try to autodetect type
$type = &$autodetect_type($self, $rootdir, $os_release);
}
}
- if ($type eq 'unmanaged') {
- $conf->{ostype} = $type;
- return $self;
- }
-
my $plugin_class = $plugins->{$type} || die "no such OS type '$type'\n";
my $plugin = $plugin_class->new($conf, $rootdir, $os_release);
# Cache some host files we need access to:
$plugin->{host_resolv_conf} = PVE::INotify::read_file('resolvconf');
- $plugin->{host_localtime} = abs_path('/etc/localtime');
+ $plugin->{host_timezone} = PVE::INotify::read_file('timezone');
+
+ abs_path('/etc/localtime') =~ m|^(/.+)| or die "invalid /etc/localtime\n"; # untaint
+ $plugin->{host_localtime} = $1;
# pass on user namespace information:
- my ($id_map, $rootuid, $rootgid) = PVE::LXC::parse_id_maps($conf);
+ my ($id_map, $root_uid, $root_gid) = PVE::LXC::parse_id_maps($conf);
if (@$id_map) {
$plugin->{id_map} = $id_map;
- $plugin->{rootuid} = $rootuid;
- $plugin->{rootgid} = $rootgid;
+ $plugin->{root_uid} = $root_uid;
+ $plugin->{root_gid} = $root_gid;
+ }
+
+ # if arch is unset, we try to autodetect it
+ if (!defined($conf->{arch})) {
+ my $arch = eval { $self->protected_call(sub { $plugin->detect_architecture() }) };
+
+ if (my $err = $@) {
+ warn "Architecture detection failed: $err" if $err;
+ }
+
+ 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";
+ }
+
+ $conf->{arch} = $arch;
}
return $self;
sub template_fixup {
my ($self) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->template_fixup($self->{conf}) });
}
-
+
sub setup_network {
my ($self) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->setup_network($self->{conf}) });
}
sub set_hostname {
my ($self) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->set_hostname($self->{conf}) });
}
sub set_dns {
my ($self) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->set_dns($self->{conf}) });
}
sub set_timezone {
my ($self) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->set_timezone($self->{conf}) });
}
sub setup_init {
my ($self) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->setup_init($self->{conf}) });
}
sub set_user_password {
my ($self, $user, $pw) = @_;
-
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub { $self->{plugin}->set_user_password($self->{conf}, $user, $pw) });
}
sub rewrite_ssh_host_keys {
my ($self) = @_;
- return if !$self->{plugin}; # unmanaged
-
my $plugin = $self->{plugin};
my $keynames = $plugin->ssh_host_key_types_to_generate();
sub post_create_hook {
my ($self, $root_password, $ssh_keys) = @_;
- return if !$self->{plugin}; # unmanaged
-
$self->protected_call(sub {
$self->{plugin}->post_create_hook($self->{conf}, $root_password, $ssh_keys);
});
sub unified_cgroupv2_support {
my ($self) = @_;
- $self->protected_call(sub { $self->{plugin}->unified_cgroupv2_support() });
+ return $self->{plugin}->unified_cgroupv2_support($self->get_ct_init_path());
}
# os-release(5):
return &$parse_os_release($data);
}
+# Checks whether /sbin/init is a symlink, and if it is, resolves it to the actual binary
+sub get_ct_init_path {
+ my ($self) = @_;
+
+ my $init = $self->protected_call(sub {
+ return $self->{plugin}->get_ct_init_path();
+ });
+
+ return $init;
+}
+
1;