1# Systemd services for lxd.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8
9 cfg = config.virtualisation.lxd;
10
11in
12
13{
14 ###### interface
15
16 options = {
17
18 virtualisation.lxd.enable =
19 mkOption {
20 type = types.bool;
21 default = false;
22 description =
23 ''
24 This option enables lxd, a daemon that manages
25 containers. Users in the "lxd" group can interact with
26 the daemon (e.g. to start or stop containers) using the
27 <command>lxc</command> command line tool, among others.
28 '';
29 };
30
31 };
32
33
34 ###### implementation
35
36 config = mkIf cfg.enable {
37
38 environment.systemPackages =
39 [ pkgs.lxd ];
40
41 systemd.services.lxd =
42 { description = "LXD Container Management Daemon";
43
44 wantedBy = [ "multi-user.target" ];
45 after = [ "systemd-udev-settle.service" ];
46
47 # TODO(wkennington): Add lvm2 and thin-provisioning-tools
48 path = with pkgs; [ acl rsync gnutar xz btrfs-progs ];
49
50 serviceConfig.ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --syslog --group lxd";
51 serviceConfig.Type = "simple";
52 serviceConfig.KillMode = "process"; # when stopping, leave the containers alone
53 };
54
55 users.extraGroups.lxd.gid = config.ids.gids.lxd;
56
57 users.extraUsers.root = {
58 subUidRanges = [ { startUid = 1000000; count = 65536; } ];
59 subGidRanges = [ { startGid = 1000000; count = 65536; } ];
60 };
61
62 };
63
64}