From 72e80cdc54f33889d4bf7b38fa58bd2d459d14e6 Mon Sep 17 00:00:00 2001 From: Patryk Wychowaniec Date: Fri, 5 Jun 2020 12:57:18 +0200 Subject: [PATCH] lxd: Add proper support for `nftables` --- nixos/modules/virtualisation/lxd.nix | 5 ++--- pkgs/tools/admin/lxd/default.nix | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/nixos/modules/virtualisation/lxd.nix b/nixos/modules/virtualisation/lxd.nix index 53b89a9f55b1..f526324e0a02 100644 --- a/nixos/modules/virtualisation/lxd.nix +++ b/nixos/modules/virtualisation/lxd.nix @@ -15,7 +15,6 @@ in ###### interface options = { - virtualisation.lxd = { enable = mkOption { type = types.bool; @@ -30,7 +29,7 @@ in package = mkOption { type = types.package; - default = pkgs.lxd; + default = pkgs.lxd.override { nftablesSupport = config.networking.nftables.enable; }; defaultText = "pkgs.lxd"; description = '' The LXD package to use. @@ -65,6 +64,7 @@ in with nixos. ''; }; + recommendedSysctlSettings = mkOption { type = types.bool; default = false; @@ -83,7 +83,6 @@ in ###### implementation config = mkIf cfg.enable { - environment.systemPackages = [ cfg.package ]; security.apparmor = { diff --git a/pkgs/tools/admin/lxd/default.nix b/pkgs/tools/admin/lxd/default.nix index f270576e684a..9da7e76657db 100644 --- a/pkgs/tools/admin/lxd/default.nix +++ b/pkgs/tools/admin/lxd/default.nix @@ -1,13 +1,21 @@ { stdenv, hwdata, pkgconfig, lxc, buildGoPackage, fetchurl , makeWrapper, acl, rsync, gnutar, xz, btrfs-progs, gzip, dnsmasq -, squashfsTools, iproute, iptables, ebtables, libcap, libco-canonical, dqlite -, raft-canonical, sqlite-replication, udev +, squashfsTools, iproute, iptables, ebtables, iptables-nftables-compat, libcap +, libco-canonical, dqlite, raft-canonical, sqlite-replication, udev , writeShellScriptBin, apparmor-profiles, apparmor-parser , criu , bash , installShellFiles +, nftablesSupport ? false }: +let + networkPkgs = if nftablesSupport then + [ iptables-nftables-compat ] + else + [ iptables ebtables ]; + +in buildGoPackage rec { pname = "lxd"; version = "4.1"; @@ -38,12 +46,14 @@ buildGoPackage rec { # test binaries, code generation rm $out/bin/{deps,macaroon-identity,generate} - wrapProgram $out/bin/lxd --prefix PATH : ${stdenv.lib.makeBinPath [ - acl rsync gnutar xz btrfs-progs gzip dnsmasq squashfsTools iproute iptables ebtables bash criu - (writeShellScriptBin "apparmor_parser" '' - exec '${apparmor-parser}/bin/apparmor_parser' -I '${apparmor-profiles}/etc/apparmor.d' "$@" - '') - ]} + wrapProgram $out/bin/lxd --prefix PATH : ${stdenv.lib.makeBinPath ( + networkPkgs + ++ [ acl rsync gnutar xz btrfs-progs gzip dnsmasq squashfsTools iproute bash criu ] + ++ [ (writeShellScriptBin "apparmor_parser" '' + exec '${apparmor-parser}/bin/apparmor_parser' -I '${apparmor-profiles}/etc/apparmor.d' "$@" + '') ] + ) + } installShellCompletion --bash go/src/github.com/lxc/lxd/scripts/bash/lxd-client '';