2014-09-21 19:29:15 +00:00
|
|
|
# LXC Configuration
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.virtualisation.lxc;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2023-12-02 14:38:44 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.lxc.members;
|
|
|
|
};
|
2014-09-21 19:29:15 +00:00
|
|
|
|
|
|
|
options.virtualisation.lxc = {
|
|
|
|
enable =
|
2023-12-02 14:41:52 +00:00
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2014-09-21 19:29:15 +00:00
|
|
|
default = false;
|
|
|
|
description =
|
|
|
|
lib.mdDoc ''
|
|
|
|
This enables Linux Containers (LXC), which provides tools
|
|
|
|
for creating and managing system or application containers
|
|
|
|
on Linux.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemConfig =
|
2023-12-02 14:41:52 +00:00
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
2014-09-21 19:29:15 +00:00
|
|
|
default = "";
|
|
|
|
description =
|
|
|
|
lib.mdDoc ''
|
2015-02-25 06:50:24 +00:00
|
|
|
This is the system-wide LXC config. See
|
|
|
|
{manpage}`lxc.system.conf(5)`.
|
2014-09-21 19:29:15 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultConfig =
|
2023-12-02 14:41:52 +00:00
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
2014-09-21 19:29:15 +00:00
|
|
|
default = "";
|
|
|
|
description =
|
|
|
|
lib.mdDoc ''
|
|
|
|
Default config (default.conf) for new containers, i.e. for
|
2015-02-25 06:50:24 +00:00
|
|
|
network config. See {manpage}`lxc.container.conf(5)`.
|
2014-09-21 19:29:15 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
usernetConfig =
|
2023-12-02 14:41:52 +00:00
|
|
|
lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
2014-09-21 19:29:15 +00:00
|
|
|
default = "";
|
|
|
|
description =
|
|
|
|
lib.mdDoc ''
|
|
|
|
This is the config file for managing unprivileged user network
|
2022-08-13 09:35:46 +00:00
|
|
|
administration access in LXC. See {manpage}`lxc-usernet(5)`.
|
2014-09-21 19:29:15 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2023-12-02 14:41:52 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2014-09-21 19:29:15 +00:00
|
|
|
environment.systemPackages = [ pkgs.lxc ];
|
|
|
|
environment.etc."lxc/lxc.conf".text = cfg.systemConfig;
|
|
|
|
environment.etc."lxc/lxc-usernet".text = cfg.usernetConfig;
|
|
|
|
environment.etc."lxc/default.conf".text = cfg.defaultConfig;
|
2017-03-14 11:34:04 +00:00
|
|
|
systemd.tmpfiles.rules = [ "d /var/lib/lxc/rootfs 0755 root root -" ];
|
2014-09-21 19:29:15 +00:00
|
|
|
|
2017-01-10 21:47:23 +00:00
|
|
|
security.apparmor.packages = [ pkgs.lxc ];
|
2020-10-18 13:36:24 +00:00
|
|
|
security.apparmor.policies = {
|
|
|
|
"bin.lxc-start".profile = ''
|
|
|
|
include ${pkgs.lxc}/etc/apparmor.d/usr.bin.lxc-start
|
|
|
|
'';
|
|
|
|
"lxc-containers".profile = ''
|
|
|
|
include ${pkgs.lxc}/etc/apparmor.d/lxc-containers
|
|
|
|
'';
|
|
|
|
};
|
2014-09-21 19:29:15 +00:00
|
|
|
};
|
|
|
|
}
|