@@ -7,6 +7,7 @@ with lib;
77let
88
99 cfg = config.virtualisation.lxd;
10+ zfsCfg = config.boot.zfs;
1011
1112in
1213
@@ -26,11 +27,40 @@ 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+ defaultText = "pkgs.lxd";
35+ description = ''
36+ The LXD package to use.
37+ '';
38+ };
39+
40+ lxcPackage = mkOption {
41+ type = types.package;
42+ default = pkgs.lxc;
43+ defaultText = "pkgs.lxc";
44+ description = ''
45+ The LXC package to use with LXD (required for AppArmor profiles).
46+ '';
47+ };
48+
49+ zfsPackage = mkOption {
50+ type = types.package;
51+ default = with pkgs; if zfsCfg.enableUnstable then zfsUnstable else zfs;
52+ defaultText = "pkgs.zfs";
53+ description = ''
54+ The ZFS package to use with LXD.
55+ '';
56+ };
57+
2958 zfsSupport = mkOption {
3059 type = types.bool;
3160 default = false;
3261 description = ''
33− enables lxd to use zfs as a storage for containers.
62+ Enables lxd to use zfs as a storage for containers.
63+
3464 This option is enabled by default if a zfs pool is configured
3565 with nixos.
3666 '';
@@ -54,15 +84,15 @@ in
5484
5585 config = mkIf cfg.enable {
5686
57− environment.systemPackages = [ pkgs.lxd ];
87+ environment.systemPackages = [ cfg.package ];
5888
5989 security.apparmor = {
6090 enable = true;
6191 profiles = [
62− "${pkgs.lxc}/etc/apparmor.d/usr.bin.lxc-start"
63− "${pkgs.lxc}/etc/apparmor.d/lxc-containers"
92+ "${cfg.lxcPackage}/etc/apparmor.d/usr.bin.lxc-start"
93+ "${cfg.lxcPackage}/etc/apparmor.d/lxc-containers"
6494 ];
65− packages = [ pkgs.lxc ];
95+ packages = [ cfg.lxcPackage ];
6696 };
6797
6898 systemd.services.lxd = {
@@ -71,14 +101,14 @@ in
71101 wantedBy = [ "multi-user.target" ];
72102 after = [ "systemd-udev-settle.service" ];
73103
74− path = lib.optional cfg.zfsSupport pkgs.zfs;
104+ path = lib.optional cfg.zfsSupport cfg.zfsPackage;
75105
76106 preStart = ''
77107 mkdir -m 0755 -p /var/lib/lxc/rootfs
78108 '';
79109
80110 serviceConfig = {
81− ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --group lxd";
111+ ExecStart = "@${cfg.package.bin}/bin/lxd lxd --group lxd";
82112 Type = "simple";
83113 KillMode = "process"; # when stopping, leave the containers alone
84114 LimitMEMLOCK = "infinity";