Merge pull request #285858 from adamcstephens/incus/refactor

incus: fix lxd-to-incus, add static client, support multi-version
This commit is contained in:
Adam C. Stephens 2024-02-05 07:50:18 -05:00 committed by GitHub
commit af25a022c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 205 additions and 140 deletions

View File

@ -18,8 +18,6 @@ import ../make-test-python.nix (
nodes.machine =
{ lib, ... }:
{
environment.systemPackages = [ pkgs.lxd-to-incus ];
virtualisation = {
diskSize = 6144;
cores = 2;

View File

@ -0,0 +1,53 @@
{
lts ? false,
lib,
buildGoModule,
fetchFromGitHub,
installShellFiles,
}:
let
releaseFile = if lts then ./lts.nix else ./latest.nix;
inherit (import releaseFile) version hash vendorHash;
in
buildGoModule rec {
pname = "incus-client";
inherit vendorHash version;
src = fetchFromGitHub {
owner = "lxc";
repo = "incus";
rev = "refs/tags/v${version}";
inherit hash;
};
CGO_ENABLED = 0;
nativeBuildInputs = [ installShellFiles ];
subPackages = [ "cmd/incus" ];
postInstall = ''
# use custom bash completion as it has extra logic for e.g. instance names
installShellCompletion --bash --name incus ./scripts/bash/incus
installShellCompletion --cmd incus \
--fish <($out/bin/incus completion fish) \
--zsh <($out/bin/incus completion zsh)
'';
# don't run the full incus test suite
doCheck = false;
meta = {
description = "Powerful system container and virtual machine manager";
homepage = "https://linuxcontainers.org/incus";
changelog = "https://github.com/lxc/incus/releases/tag/v${version}";
license = lib.licenses.asl20;
maintainers = lib.teams.lxc.members;
platforms = lib.platforms.unix;
mainProgram = "incus";
};
}

View File

@ -0,0 +1,5 @@
{
hash = "sha256-3eWkQT2P69ZfN62H9B4WLnmlUOGkpzRR0rctgchP+6A=";
version = "0.5.1";
vendorHash = "sha256-2ZJU7WshN4UIbJv55bFeo9qiAQ/wxu182mnz7pE60xA=";
}

View File

@ -0,0 +1,3 @@
# this release doesn't exist yet, but satisfay the by-name checks
# will be added as incus-lts in all-packages.nix once ready
{ }

View File

@ -1,42 +1,49 @@
{ lib
, incus-unwrapped
, linkFarm
, makeWrapper
, stdenv
, symlinkJoin
, writeShellScriptBin
, acl
, apparmor-parser
, apparmor-profiles
, attr
, bash
, btrfs-progs
, cdrkit
, criu
, dnsmasq
, e2fsprogs
, getent
, gnutar
, gptfdisk
, gzip
, iproute2
, iptables
, kmod
, lvm2
, minio
, nftables
, OVMF
, qemu_kvm
, qemu-utils
, rsync
, spice-gtk
, squashfsTools
, thin-provisioning-tools
, util-linux
, virtiofsd
, xz
{
lts ? false,
lib,
callPackage,
linkFarm,
makeWrapper,
stdenv,
symlinkJoin,
writeShellScriptBin,
acl,
apparmor-parser,
apparmor-profiles,
attr,
bash,
btrfs-progs,
cdrkit,
criu,
dnsmasq,
e2fsprogs,
getent,
gnutar,
gptfdisk,
gzip,
iproute2,
iptables,
kmod,
lvm2,
minio,
nftables,
OVMF,
qemu_kvm,
qemu-utils,
rsync,
spice-gtk,
squashfsTools,
thin-provisioning-tools,
util-linux,
virtiofsd,
xz,
}:
let
unwrapped = callPackage ./unwrapped.nix { inherit lts; };
client = callPackage ./client.nix { inherit lts; };
name = "incus${lib.optionalString lts "-lts"}";
binPath = lib.makeBinPath [
acl
attr
@ -70,9 +77,7 @@ let
'')
];
clientBinPath = [
spice-gtk
];
clientBinPath = [ spice-gtk ];
ovmf-2mb = OVMF.override {
secureBoot = true;
@ -98,24 +103,57 @@ let
# mimic ovmf from https://github.com/canonical/incus-pkg-snap/blob/3abebe1dfeb20f9b7729556960c7e9fe6ad5e17c/snapcraft.yaml#L378
# also found in /snap/incus/current/share/qemu/ on a snap install
ovmf = linkFarm "incus-ovmf" [
{ name = "OVMF_CODE.2MB.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd"; }
{ name = "OVMF_CODE.4MB.CSM.fd"; path = "${ovmf-4mb-csm.fd}/FV/${ovmf-prefix}_CODE.fd"; }
{ name = "OVMF_CODE.4MB.fd"; path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_CODE.fd"; }
{ name = "OVMF_CODE.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd"; }
{
name = "OVMF_CODE.2MB.fd";
path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd";
}
{
name = "OVMF_CODE.4MB.CSM.fd";
path = "${ovmf-4mb-csm.fd}/FV/${ovmf-prefix}_CODE.fd";
}
{
name = "OVMF_CODE.4MB.fd";
path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_CODE.fd";
}
{
name = "OVMF_CODE.fd";
path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_CODE.fd";
}
{ name = "OVMF_VARS.2MB.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{ name = "OVMF_VARS.2MB.ms.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{ name = "OVMF_VARS.4MB.CSM.fd"; path = "${ovmf-4mb-csm.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{ name = "OVMF_VARS.4MB.fd"; path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{ name = "OVMF_VARS.4MB.ms.fd"; path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{ name = "OVMF_VARS.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{ name = "OVMF_VARS.ms.fd"; path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd"; }
{
name = "OVMF_VARS.2MB.fd";
path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
}
{
name = "OVMF_VARS.2MB.ms.fd";
path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
}
{
name = "OVMF_VARS.4MB.CSM.fd";
path = "${ovmf-4mb-csm.fd}/FV/${ovmf-prefix}_VARS.fd";
}
{
name = "OVMF_VARS.4MB.fd";
path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd";
}
{
name = "OVMF_VARS.4MB.ms.fd";
path = "${ovmf-4mb.fd}/FV/${ovmf-prefix}_VARS.fd";
}
{
name = "OVMF_VARS.fd";
path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
}
{
name = "OVMF_VARS.ms.fd";
path = "${ovmf-2mb.fd}/FV/${ovmf-prefix}_VARS.fd";
}
];
in
symlinkJoin {
name = "incus-${incus-unwrapped.version}";
name = "${name}-${unwrapped.version}";
paths = [ incus-unwrapped ];
paths = [ unwrapped ];
nativeBuildInputs = [ makeWrapper ];
@ -126,8 +164,10 @@ symlinkJoin {
'';
passthru = {
inherit (incus-unwrapped) tests;
inherit client unwrapped;
inherit (unwrapped) tests;
};
inherit (incus-unwrapped) meta pname version;
inherit (unwrapped) meta pname version;
}

View File

@ -1,41 +1,51 @@
{ lib
, buildGoModule
, fetchFromGitHub
, acl
, cowsql
, hwdata
, libcap
, lxc
, pkg-config
, sqlite
, udev
, installShellFiles
, nix-update-script
, nixosTests
{
lts ? false,
lib,
buildGoModule,
fetchFromGitHub,
writeShellScript,
acl,
cowsql,
hwdata,
libcap,
lxc,
pkg-config,
sqlite,
udev,
installShellFiles,
nixosTests,
}:
let
releaseFile = if lts then ./lts.nix else ./latest.nix;
inherit (import releaseFile) version hash vendorHash;
name = "incus${lib.optionalString lts "-lts"}";
in
buildGoModule rec {
pname = "incus-unwrapped";
version = "0.5.1";
pname = "${name}-unwrapped";
inherit vendorHash version;
src = fetchFromGitHub {
owner = "lxc";
repo = "incus";
rev = "refs/tags/v${version}";
hash = "sha256-3eWkQT2P69ZfN62H9B4WLnmlUOGkpzRR0rctgchP+6A=";
rev = "v${version}";
inherit hash;
};
vendorHash = "sha256-2ZJU7WshN4UIbJv55bFeo9qiAQ/wxu182mnz7pE60xA=";
postPatch = ''
substituteInPlace internal/usbid/load.go \
--replace "/usr/share/misc/usb.ids" "${hwdata}/share/hwdata/usb.ids"
'';
excludedPackages = [
# statically compile these
"cmd/incus-agent"
"cmd/incus-migrate"
"cmd/lxd-to-incus"
# oidc test requires network
"test/mini-oidc"
];
@ -53,7 +63,10 @@ buildGoModule rec {
udev.dev
];
ldflags = [ "-s" "-w" ];
ldflags = [
"-s"
"-w"
];
tags = [ "libsqlite3" ];
# required for go-cowsql.
@ -64,13 +77,15 @@ buildGoModule rec {
'';
preCheck =
let skippedTests = [
"TestValidateConfig"
"TestConvertNetworkConfig"
"TestConvertStorageConfig"
"TestSnapshotCommon"
"TestContainerTestSuite"
]; in
let
skippedTests = [
"TestValidateConfig"
"TestConvertNetworkConfig"
"TestConvertStorageConfig"
"TestSnapshotCommon"
"TestContainerTestSuite"
];
in
''
# Disable tests requiring local operations
buildFlagsArray+=("-run" "[^(${builtins.concatStringsSep "|" skippedTests})]")
@ -85,15 +100,14 @@ buildGoModule rec {
--zsh <($out/bin/incus completion zsh)
'';
passthru = {
tests.incus = nixosTests.incus;
updateScript = nix-update-script {
extraArgs = [
"-vr" "v\(.*\)"
];
};
updateScript = writeShellScript "update-incus" ''
nix-update ${name}.unwrapped -vr 'v(.*)' --override-filename pkgs/by-name/in/incus/${
if lts then "lts" else "latest"
}.nix
'';
};
meta = {

View File

@ -1,48 +0,0 @@
{ lib
, buildGoModule
, fetchFromGitHub
, fetchpatch
, nix-update-script
}:
buildGoModule rec {
pname = "lxd-to-incus";
version = "0.4.0";
src = fetchFromGitHub {
owner = "lxc";
repo = "incus";
rev = "refs/tags/v${version}";
hash = "sha256-crWepf5j3Gd1lhya2DGIh/to7l+AnjKJPR+qUd9WOzw=";
};
patches = [
# create migration touch file, remove > 0.4.0
(fetchpatch {
url = "https://github.com/lxc/incus/commit/edc5fd2a9baccfb7b6814a440e2947cbb580afcf.diff";
hash = "sha256-ffQfMFrKDPuLU4jVbG/VGHSO3DmeHw30ATJ8yxJAoHQ=";
})
];
modRoot = "cmd/lxd-to-incus";
vendorHash = "sha256-cBAqJz3Y4CqyxTt7u/4mXoQPKmKgQ3gYJV1NiC/H+TA=";
CGO_ENABLED = 0;
passthru = {
updateScript = nix-update-script {
extraArgs = [
"-vr" "v\(.*\)"
];
};
};
meta = {
description = "LXD to Incus migration tool";
homepage = "https://linuxcontainers.org/incus";
license = lib.licenses.asl20;
maintainers = lib.teams.lxc.members;
platforms = lib.platforms.linux;
};
}