Skip to content

Commit

Permalink
Source build of lxd-agent. SecureBoot enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenewey committed Mar 20, 2021
1 parent 7a01dfe commit b0c1746
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
14 changes: 6 additions & 8 deletions etc/nixos/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@

# the good stuff...
virtualisation.lxd.enable = true;
virtualisation.lxd.zfsSupport = true;
virtualisation.lxd.zfsSupport = true; # zfs is recommended
virtualisation.lxd.recommendedSysctlSettings = true;
systemd.services.lxd.path = with pkgs; [

# the lxd-agent in nixpkgs is dynamically linked and will fail in your guest VM!
# this provides a statically compiled version pulled from this repo
# this builds a statically compiled version
( import ./lxd-agent.nix )

# lxd won't find virtiofsd without making sure it's in the path
# lxd won't find virtiofsd or virtfs-proxy-helper without making sure they're in the path
( import ./virtiofsd.nix )

# the lxd nixpkg doesn't know it needs kvm in its path to run qemu!
Expand All @@ -118,11 +119,8 @@
systemd.services.lxd.environment = {

# lxd will look for EFI firmware in /usr/share, but will not find it there
# so we need to tell it about the OVMF nixpkg
# Ideally, we've used OVMF-secureBoot, but this doesn't actually seem to
# include a signed EFI, so make sure to run:
# lxc profile set default security.secureboot false
LXD_OVMF_PATH = "${pkgs.OVMF.fd.outPath}/FV";
# so we need to tell it about our metapackage
LXD_OVMF_PATH = ( import ./ovmf-meta.nix );

};

Expand Down
34 changes: 27 additions & 7 deletions etc/nixos/lxd-agent.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
with import <nixpkgs> {};

stdenv.mkDerivation rec {
stdenv.mkDerivation buildGoPackage rec {
name = "lxd-agent";
version = "4.5"; # modify the version if using newer LXD

goPackagePath = "github.com/lxc/lxd";

buildFlags = [ "-ldflags=-extldflags=-static" "-ldflags=-s" "-ldflags=-w" "-tags libsqlite3" ];

src = fetchurl {
url = https://github.com/stevenewey/lxd-vms-on-nixos/raw/master/lxd-agent/lxd-agent;
sha256 = "4c17cb711a95b7d2fd1ec90f02f94ec0b4bbd89e556e188576ece66f91666bb7";
url = "https://github.com/lxc/lxd/releases/download/lxd-${version}/lxd-${version}.tar.gz";
sha256 = "1nszzcyn8kvpnxppjbxky5x9a8n0jfmhy20j6nrwm3196gd6hirr"; # update this when changing LXD version
};
buildCommand = ''
mkdir -p $out/bin
cp $src $out/bin/lxd-agent
chmod +x $out/bin/lxd-agent

subPackages = [ "lxd-agent" ];

preConfigure = ''
export CGO_ENABLED=0
'';

postPatch = ''
substituteInPlace shared/usbid/load.go \
--replace "/usr/share/misc/usb.ids" "${hwdata}/share/hwdata/usb.ids"
'';

preBuild = ''
# unpack vendor
pushd go/src/github.com/lxc/lxd
rm _dist/src/github.com/lxc/lxd
cp -r _dist/src/* ../../..
popd
'';
}
13 changes: 13 additions & 0 deletions etc/nixos/ovmf-meta.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with import <nixpkgs> {};

# with this configuration, LXD will only support secureboot, which is the default

stdenv.mkDerivation rec {
name = "ovmf-meta";
buildCommand = ''
mkdir -p $out
cp ${pkgs.OVMF-secureBoot.fd}/FV/OVMF.fd $out/
cp ${pkgs.OVMF-secureBoot.fd}/FV/OVMF_CODE.fd $out/
cp ${pkgs.OVMF-secureBoot.fd}/FV/OVMF_VARS.fd $out/OVMF_VARS.ms.fd
'';
}
1 change: 1 addition & 0 deletions etc/nixos/virtiofsd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ stdenv.mkDerivation rec {
buildCommand = ''
mkdir -p $out/bin
ln -s ${pkgs.kvm}/libexec/virtiofsd $out/bin/
ln -s ${pkgs.kvm}/libexec/virtfs-proxy-helper $out/bin/
'';
}
2 changes: 2 additions & 0 deletions lxd-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ The agent itself is unversioned.
The [license is included](COPYING).

The source can be found at https://github.com/lxc/lxd

**UPDATE**: This is no longer required by the configuration now provided, which builds the agent from source. This remains here for legacy purposes.

0 comments on commit b0c1746

Please sign in to comment.