summary refs log tree commit diff
path: root/nixos/modules/virtualisation/lxd.nix
blob: b1ff0337994ee7d7a1c04abb46662c8379b77983 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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 ];

    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
        path = with pkgs; [ acl rsync gnutar xz btrfs-progs gzip dnsmasq squashfsTools iproute iptables ];

        serviceConfig.ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --syslog --group lxd";
        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; } ];
    };

  };

}