blob: 012695df78ee504115fd44372d446ac6b22d0a8a (
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
|
{ pkgs, ... }:
let
container = {
name = "ubu";
distro = "ubuntu";
release = "jammy";
};
bridge = "lan";
in
{
virtualisation.lxc.enable = true;
environment.systemPackages = with pkgs; [ wget ];
systemd.services."lxc-${container.name}-provision" = {
description = "auto provision ${container.name} lxc container";
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
stopIfChanged = false;
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
path = with pkgs; [
wget
lxc
util-linux
gnutar
xz
gawk
];
script = ''
if ! lxc-ls | grep -q ${container.name}; then
lxc-create -n ${container.name} -t download -- \
--arch amd64 \
--release ${container.release} \
--dist ${container.distro}
sed 's/lxcbr0/${bridge}/g' -i /var/lib/lxc/${container.name}/config
fi
lxc-start -n ${container.name}
'';
preStop = "lxc-stop --name ${container.name}";
};
}
|