2015-09-14 06:27:31 +00:00
|
|
|
# Systemd services for lxd.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.virtualisation.lxd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
virtualisation.lxd.enable =
|
|
|
|
mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
This option enables lxd, a daemon that manages
|
|
|
|
containers. Users in the "lxd" group can interact with
|
|
|
|
the daemon (e.g. to start or stop containers) using the
|
|
|
|
<command>lxc</command> command line tool, among others.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages =
|
|
|
|
[ pkgs.lxd ];
|
|
|
|
|
2018-02-10 08:18:53 +00:00
|
|
|
security.apparmor = {
|
|
|
|
enable = true;
|
|
|
|
profiles = [
|
|
|
|
"${pkgs.lxc}/etc/apparmor.d/usr.bin.lxc-start"
|
|
|
|
"${pkgs.lxc}/etc/apparmor.d/lxc-containers"
|
|
|
|
];
|
|
|
|
packages = [ pkgs.lxc ];
|
|
|
|
};
|
|
|
|
|
2015-09-14 06:27:31 +00:00
|
|
|
systemd.services.lxd =
|
|
|
|
{ description = "LXD Container Management Daemon";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "systemd-udev-settle.service" ];
|
|
|
|
|
|
|
|
# TODO(wkennington): Add lvm2 and thin-provisioning-tools
|
2017-05-24 18:29:38 +00:00
|
|
|
path = with pkgs; [ acl rsync gnutar xz btrfs-progs gzip dnsmasq squashfsTools iproute iptables ];
|
2015-09-14 06:27:31 +00:00
|
|
|
|
2018-02-10 08:18:53 +00:00
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p /var/lib/lxc/rootfs
|
|
|
|
'';
|
|
|
|
|
2016-06-19 19:30:36 +00:00
|
|
|
serviceConfig.ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --syslog --group lxd";
|
2015-09-14 06:27:31 +00:00
|
|
|
serviceConfig.Type = "simple";
|
|
|
|
serviceConfig.KillMode = "process"; # when stopping, leave the containers alone
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.lxd.gid = config.ids.gids.lxd;
|
|
|
|
|
|
|
|
users.extraUsers.root = {
|
|
|
|
subUidRanges = [ { startUid = 1000000; count = 65536; } ];
|
|
|
|
subGidRanges = [ { startGid = 1000000; count = 65536; } ];
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|