nixos/lxc: add package option and use for incus/lxd

This commit is contained in:
Adam Stephens 2024-04-22 08:31:05 -04:00
parent ee1428c654
commit f171f4ffd4
No known key found for this signature in database
3 changed files with 16 additions and 9 deletions

View File

@ -111,7 +111,12 @@ in
package = lib.mkPackageOption pkgs "incus-lts" { }; package = lib.mkPackageOption pkgs "incus-lts" { };
lxcPackage = lib.mkPackageOption pkgs "lxc" { }; lxcPackage = lib.mkOption {
type = lib.types.package;
default = config.virtualisation.lxc.package;
defaultText = lib.literalExpression "config.virtualisation.lxc.package";
description = "The lxc package to use.";
};
clientPackage = lib.mkOption { clientPackage = lib.mkOption {
type = lib.types.package; type = lib.types.package;

View File

@ -32,6 +32,7 @@ in
{manpage}`lxc.system.conf(5)`. {manpage}`lxc.system.conf(5)`.
''; '';
}; };
package = lib.mkPackageOption pkgs "lxc" { };
defaultConfig = defaultConfig =
lib.mkOption { lib.mkOption {
@ -57,19 +58,19 @@ in
###### implementation ###### implementation
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.lxc ]; environment.systemPackages = [ cfg.package ];
environment.etc."lxc/lxc.conf".text = cfg.systemConfig; environment.etc."lxc/lxc.conf".text = cfg.systemConfig;
environment.etc."lxc/lxc-usernet".text = cfg.usernetConfig; environment.etc."lxc/lxc-usernet".text = cfg.usernetConfig;
environment.etc."lxc/default.conf".text = cfg.defaultConfig; environment.etc."lxc/default.conf".text = cfg.defaultConfig;
systemd.tmpfiles.rules = [ "d /var/lib/lxc/rootfs 0755 root root -" ]; systemd.tmpfiles.rules = [ "d /var/lib/lxc/rootfs 0755 root root -" ];
security.apparmor.packages = [ pkgs.lxc ]; security.apparmor.packages = [ cfg.package ];
security.apparmor.policies = { security.apparmor.policies = {
"bin.lxc-start".profile = '' "bin.lxc-start".profile = ''
include ${pkgs.lxc}/etc/apparmor.d/usr.bin.lxc-start include ${cfg.package}/etc/apparmor.d/usr.bin.lxc-start
''; '';
"lxc-containers".profile = '' "lxc-containers".profile = ''
include ${pkgs.lxc}/etc/apparmor.d/lxc-containers include ${cfg.package}/etc/apparmor.d/lxc-containers
''; '';
}; };
}; };

View File

@ -35,10 +35,11 @@ in {
package = lib.mkPackageOption pkgs "lxd-lts" { }; package = lib.mkPackageOption pkgs "lxd-lts" { };
lxcPackage = lib.mkPackageOption pkgs "lxc" { lxcPackage = lib.mkOption {
extraDescription = '' type = lib.types.package;
Required for AppArmor profiles. default = config.virtualisation.lxc.package;
''; defaultText = lib.literalExpression "config.virtualisation.lxc.package";
description = "The lxc package to use.";
}; };
zfsSupport = lib.mkOption { zfsSupport = lib.mkOption {