Skip to content

Commit

Permalink
lxd: 2.16 -> 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Apr 14, 2018
1 parent 615599c commit 7663de1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 205 deletions.
2 changes: 2 additions & 0 deletions nixos/modules/tasks/filesystems/zfs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ in
}
];

virtualisation.lxd.zfsSupport = true;

boot = {
kernelModules = [ "spl" "zfs" ] ;
extraModulePackages = with packages; [ spl zfs ];
Expand Down
5 changes: 4 additions & 1 deletion nixos/modules/virtualisation/lxc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ in
systemd.tmpfiles.rules = [ "d /var/lib/lxc/rootfs 0755 root root -" ];

security.apparmor.packages = [ pkgs.lxc ];
security.apparmor.profiles = [ "${pkgs.lxc}/etc/apparmor.d/lxc-containers" ];
security.apparmor.profiles = [
"${pkgs.lxc}/etc/apparmor.d/lxc-containers"
"${pkgs.lxc}/etc/apparmor.d/usr.bin.lxc-start"
];
};
}
60 changes: 33 additions & 27 deletions nixos/modules/virtualisation/lxd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ in

options = {

virtualisation.lxd.enable =
mkOption {
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.
'';
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.
'';
};

zfsSupport = mkOption {
type = types.bool;
default = false;
description = ''
enables lxd to use zfs as a storage for containers.
This option is enabled by default if a zfs pool is configured
with nixos.
'';
};
};
};


###### implementation

config = mkIf cfg.enable {

environment.systemPackages =
[ pkgs.lxd ];
environment.systemPackages = [ pkgs.lxd ];

security.apparmor = {
enable = true;
Expand All @@ -47,31 +53,31 @@ in
packages = [ pkgs.lxc ];
};

systemd.services.lxd =
{ description = "LXD Container Management Daemon";
systemd.services.lxd = {
description = "LXD Container Management Daemon";

wantedBy = [ "multi-user.target" ];
after = [ "systemd-udev-settle.service" ];
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 ];
path = lib.optional cfg.zfsSupport pkgs.zfs;

preStart = ''
mkdir -m 0755 -p /var/lib/lxc/rootfs
'';
preStart = ''
mkdir -m 0755 -p /var/lib/lxc/rootfs
'';

serviceConfig.ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --syslog --group lxd";
serviceConfig.Type = "simple";
serviceConfig.KillMode = "process"; # when stopping, leave the containers alone
serviceConfig = {
ExecStart = "@${pkgs.lxd.bin}/bin/lxd lxd --group lxd";
Type = "simple";
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; } ];
};

};

}
38 changes: 26 additions & 12 deletions pkgs/tools/admin/lxd/default.nix
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
{ stdenv, lib, pkgconfig, lxc, buildGoPackage, fetchFromGitHub }:
{ stdenv, lib, pkgconfig, lxc, buildGoPackage, fetchurl
, makeWrapper, acl, rsync, gnutar, xz, btrfs-progs, gzip, dnsmasq, squashfsTools, iproute, iptables
}:

buildGoPackage rec {
name = "lxd-${version}";
version = "2.16";
rev = "lxd-${version}";
name = "lxd-3.0.0";

goPackagePath = "github.com/lxc/lxd";

src = fetchFromGitHub {
inherit rev;
owner = "lxc";
repo = "lxd";
sha256 = "0i2mq9m8k9kznwz1i0xb48plp1ffpzvbdrvqvagis4sm17yab3fn";
src = fetchurl {
url = "https://github.com/lxc/lxd/releases/download/${name}/${name}.tar.gz";
sha256 = "0m5prdf9sk8k5bws1zva4n9ycggmy76wnjr6wb423066pszz24ww";
};

goDeps = ./deps.nix;
preBuild = ''
# unpack vendor
pushd go/src/github.com/lxc/lxd
rm dist/src/github.com/lxc/lxd
cp -r dist/src/* ../../..
rm -r dist
popd
'';

nativeBuildInputs = [ pkgconfig ];
buildInputs = [ lxc ];
postInstall = ''
# binaries from test/
rm $bin/bin/{deps,macaroon-identity}
wrapProgram $bin/bin/lxd --prefix PATH ":" ${stdenv.lib.makeBinPath [
acl rsync gnutar xz btrfs-progs gzip dnsmasq squashfsTools iproute iptables
]}
'';

nativeBuildInputs = [ pkgconfig makeWrapper ];
buildInputs = [ lxc acl ];

meta = with stdenv.lib; {
description = "Daemon based on liblxc offering a REST API to manage containers";
Expand Down
165 changes: 0 additions & 165 deletions pkgs/tools/admin/lxd/deps.nix

This file was deleted.

0 comments on commit 7663de1

Please sign in to comment.