@@ -7,6 +7,7 @@ with lib;
77let
88
99 cfg = config.virtualisation.lxd;
10+ zfsCfg = config.boot.zfs;
1011
1112in
1213
@@ -26,11 +27,38 @@ in
2627 <command>lxc</command> command line tool, among others.
2728 '';
2829 };
30+
31+ package = mkOption {
32+ type = types.package;
33+ default = pkgs.lxd;
34+ description = ''
35+ The LXD package to use.
36+ '';
37+ };
38+
39+ lxcPackage = mkOption {
40+ type = types.package;
41+ default = pkgs.lxc;
42+ description = ''
43+ The LXC package to use with LXD (required for AppArmor profiles).
44+ '';
45+ };
46+
47+ zfsPackage = mkOption {
48+ type = types.package;
49+ default = with pkgs; if zfsCfg.enableUnstable then zfsUnstable else zfs;
50+ defaultText = "pkgs.zfs";
51+ description = ''
52+ The ZFS package to use with LXD.
53+ '';
54+ };
55+
2956 zfsSupport = mkOption {
3057 type = types.bool;
3158 default = false;
3259 description = ''
33− enables lxd to use zfs as a storage for containers.
60+ Enables lxd to use zfs as a storage for containers.
61+
3462 This option is enabled by default if a zfs pool is configured
3563 with nixos.
3664 '';
@@ -54,15 +82,15 @@ in
5482
5583 config = mkIf cfg.enable {
5684
57− environment.systemPackages = [ pkgs.lxd ];
85+ environment.systemPackages = [ cfg.package ];
5886
5987 security.apparmor = {
6088 enable = true;
6189 profiles = [
62− "${pkgs.lxc}/etc/apparmor.d/usr.bin.lxc-start"
63− "${pkgs.lxc}/etc/apparmor.d/lxc-containers"
90+ "${cfg.lxcPackage}/etc/apparmor.d/usr.bin.lxc-start"
91+ "${cfg.lxcPackage}/etc/apparmor.d/lxc-containers"
6492 ];
65− packages = [ pkgs.lxc ];
93+ packages = [ cfg.lxcPackage ];
6694 };
6795
6896 systemd.services.lxd = {
@@ -71,14 +99,14 @@ in
7199 wantedBy = [ "multi-user.target" ];
72100 after = [ "systemd-udev-settle.service" ];
73101
74− path = lib.optional cfg.zfsSupport pkgs.zfs;
102+ path = lib.optional cfg.zfsSupport cfg.zfsPackage;
75103
76104 preStart = ''
77105 mkdir -m 0755 -p /var/lib/lxc/rootfs
78106 '';
79107
80108 serviceConfig = {
81− ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --group lxd";
109+ ExecStart = "@${cfg.package.bin}/bin/lxd lxd --group lxd";
82110 Type = "simple";
83111 KillMode = "process"; # when stopping, leave the containers alone
84112 LimitMEMLOCK = "infinity";