Skip to content

Commit 33b9d57

Browse files
incus: fix container tests from image rename (#360305)
2 parents e6e8a6a + c494726 commit 33b9d57

File tree

14 files changed

+609
-488
lines changed

14 files changed

+609
-488
lines changed

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,6 @@ ce21e97a1f20dee15da85c084f9d1148d84f853b
212212

213213
# format files with nixfmt (#347275)
214214
adb9714bd909df283c66bbd641bd631ff50a4260
215+
216+
# treewide: incus packages
217+
9ab59bb5fb943ad6740f64f5a79eae9642fb8211

nixos/modules/virtualisation/lxc-image-metadata.nix

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,71 @@
1-
{ lib, config, pkgs, ... }:
1+
{
2+
lib,
3+
config,
4+
pkgs,
5+
...
6+
}:
27

38
let
4-
templateSubmodule = {...}: {
5-
options = {
6-
enable = lib.mkEnableOption "this template";
9+
templateSubmodule =
10+
{ ... }:
11+
{
12+
options = {
13+
enable = lib.mkEnableOption "this template";
714

8-
target = lib.mkOption {
9-
description = "Path in the container";
10-
type = lib.types.path;
11-
};
12-
template = lib.mkOption {
13-
description = ".tpl file for rendering the target";
14-
type = lib.types.path;
15-
};
16-
when = lib.mkOption {
17-
description = "Events which trigger a rewrite (create, copy)";
18-
type = lib.types.listOf (lib.types.str);
19-
};
20-
properties = lib.mkOption {
21-
description = "Additional properties";
22-
type = lib.types.attrs;
23-
default = {};
15+
target = lib.mkOption {
16+
description = "Path in the container";
17+
type = lib.types.path;
18+
};
19+
template = lib.mkOption {
20+
description = ".tpl file for rendering the target";
21+
type = lib.types.path;
22+
};
23+
when = lib.mkOption {
24+
description = "Events which trigger a rewrite (create, copy)";
25+
type = lib.types.listOf (lib.types.str);
26+
};
27+
properties = lib.mkOption {
28+
description = "Additional properties";
29+
type = lib.types.attrs;
30+
default = { };
31+
};
2432
};
2533
};
26-
};
2734

28-
toYAML = name: data: pkgs.writeText name (lib.generators.toYAML {} data);
35+
toYAML = name: data: pkgs.writeText name (lib.generators.toYAML { } data);
2936

3037
cfg = config.virtualisation.lxc;
31-
templates = if cfg.templates != {} then let
32-
list = lib.mapAttrsToList (name: value: { inherit name; } // value)
33-
(lib.filterAttrs (name: value: value.enable) cfg.templates);
34-
in
35-
{
36-
files = map (tpl: {
37-
source = tpl.template;
38-
target = "/templates/${tpl.name}.tpl";
39-
}) list;
40-
properties = lib.listToAttrs (map (tpl: lib.nameValuePair tpl.target {
41-
when = tpl.when;
42-
template = "${tpl.name}.tpl";
43-
properties = tpl.properties;
44-
}) list);
45-
}
46-
else { files = []; properties = {}; };
38+
templates =
39+
if cfg.templates != { } then
40+
let
41+
list = lib.mapAttrsToList (name: value: { inherit name; } // value) (
42+
lib.filterAttrs (name: value: value.enable) cfg.templates
43+
);
44+
in
45+
{
46+
files = map (tpl: {
47+
source = tpl.template;
48+
target = "/templates/${tpl.name}.tpl";
49+
}) list;
50+
properties = lib.listToAttrs (
51+
map (
52+
tpl:
53+
lib.nameValuePair tpl.target {
54+
when = tpl.when;
55+
template = "${tpl.name}.tpl";
56+
properties = tpl.properties;
57+
}
58+
) list
59+
);
60+
}
61+
else
62+
{
63+
files = [ ];
64+
properties = { };
65+
};
4766

48-
in {
67+
in
68+
{
4969
imports = [
5070
../image/file-options.nix
5171
];
@@ -59,7 +79,7 @@ in {
5979
templates = lib.mkOption {
6080
description = "Templates for LXD";
6181
type = lib.types.attrsOf (lib.types.submodule templateSubmodule);
62-
default = {};
82+
default = { };
6383
example = lib.literalExpression ''
6484
{
6585
# create /etc/hostname on container creation
@@ -91,7 +111,10 @@ in {
91111
};
92112

93113
config = {
94-
system.nixos.tags = [ "lxc" "metadata" ];
114+
system.nixos.tags = [
115+
"lxc"
116+
"metadata"
117+
];
95118
image.extension = "tar.xz";
96119
image.filePath = "tarball/${config.image.fileName}";
97120
system.build.image = config.system.build.metadata;
@@ -100,7 +123,9 @@ in {
100123
contents = [
101124
{
102125
source = toYAML "metadata.yaml" {
103-
architecture = builtins.elemAt (builtins.match "^([a-z0-9_]+).+" (toString pkgs.stdenv.hostPlatform.system)) 0;
126+
architecture = builtins.elemAt (builtins.match "^([a-z0-9_]+).+" (
127+
toString pkgs.stdenv.hostPlatform.system
128+
)) 0;
104129
creation_date = 1;
105130
properties = {
106131
description = "${config.system.nixos.distroName} ${config.system.nixos.codeName} ${config.system.nixos.label} ${pkgs.stdenv.hostPlatform.system}";

nixos/modules/virtualisation/lxc-instance-common.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{lib, ...}:
1+
{ lib, ... }:
22

33
{
44
meta = {

nixos/modules/virtualisation/lxc.nix

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# LXC Configuration
22

3-
{ config, lib, pkgs, ... }:
3+
{
4+
config,
5+
lib,
6+
pkgs,
7+
...
8+
}:
49

510
let
611
cfg = config.virtualisation.lxc;
@@ -12,58 +17,53 @@ in
1217
};
1318

1419
options.virtualisation.lxc = {
15-
enable =
16-
lib.mkOption {
17-
type = lib.types.bool;
18-
default = false;
19-
description = ''
20-
This enables Linux Containers (LXC), which provides tools
21-
for creating and managing system or application containers
22-
on Linux.
23-
'';
24-
};
20+
enable = lib.mkOption {
21+
type = lib.types.bool;
22+
default = false;
23+
description = ''
24+
This enables Linux Containers (LXC), which provides tools
25+
for creating and managing system or application containers
26+
on Linux.
27+
'';
28+
};
2529

2630
unprivilegedContainers = lib.mkEnableOption "support for unprivileged users to launch containers";
2731

28-
systemConfig =
29-
lib.mkOption {
30-
type = lib.types.lines;
31-
default = "";
32-
description = ''
33-
This is the system-wide LXC config. See
34-
{manpage}`lxc.system.conf(5)`.
35-
'';
36-
};
32+
systemConfig = lib.mkOption {
33+
type = lib.types.lines;
34+
default = "";
35+
description = ''
36+
This is the system-wide LXC config. See
37+
{manpage}`lxc.system.conf(5)`.
38+
'';
39+
};
3740
package = lib.mkPackageOption pkgs "lxc" { };
3841

39-
defaultConfig =
40-
lib.mkOption {
41-
type = lib.types.lines;
42-
default = "";
43-
description = ''
44-
Default config (default.conf) for new containers, i.e. for
45-
network config. See {manpage}`lxc.container.conf(5)`.
46-
'';
47-
};
42+
defaultConfig = lib.mkOption {
43+
type = lib.types.lines;
44+
default = "";
45+
description = ''
46+
Default config (default.conf) for new containers, i.e. for
47+
network config. See {manpage}`lxc.container.conf(5)`.
48+
'';
49+
};
4850

49-
usernetConfig =
50-
lib.mkOption {
51-
type = lib.types.lines;
52-
default = "";
53-
description = ''
54-
This is the config file for managing unprivileged user network
55-
administration access in LXC. See {manpage}`lxc-usernet(5)`.
56-
'';
57-
};
51+
usernetConfig = lib.mkOption {
52+
type = lib.types.lines;
53+
default = "";
54+
description = ''
55+
This is the config file for managing unprivileged user network
56+
administration access in LXC. See {manpage}`lxc-usernet(5)`.
57+
'';
58+
};
5859

59-
bridgeConfig =
60-
lib.mkOption {
61-
type = lib.types.lines;
62-
default = "";
63-
description = ''
64-
This is the config file for override lxc-net bridge default settings.
65-
'';
66-
};
60+
bridgeConfig = lib.mkOption {
61+
type = lib.types.lines;
62+
default = "";
63+
description = ''
64+
This is the config file for override lxc-net bridge default settings.
65+
'';
66+
};
6767
};
6868

6969
###### implementation
@@ -88,7 +88,7 @@ in
8888
};
8989

9090
# We don't need the `lxc-user` group, unless the unprivileged containers are enabled.
91-
users.groups = lib.mkIf cfg.unprivilegedContainers { lxc-user = {}; };
91+
users.groups = lib.mkIf cfg.unprivilegedContainers { lxc-user = { }; };
9292

9393
# `lxc-user-nic` needs suid to attach to bridge for unpriv containers.
9494
security.wrappers = lib.mkIf cfg.unprivilegedContainers {
@@ -108,7 +108,12 @@ in
108108
lxc-net = {
109109
enable = true;
110110
wantedBy = [ "multi-user.target" ];
111-
path = [ pkgs.iproute2 pkgs.iptables pkgs.getent pkgs.dnsmasq ];
111+
path = [
112+
pkgs.iproute2
113+
pkgs.iptables
114+
pkgs.getent
115+
pkgs.dnsmasq
116+
];
112117
};
113118
};
114119
};

nixos/modules/virtualisation/lxcfs.nix

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
# LXC Configuration
22

3-
{ config, lib, pkgs, ... }:
3+
{
4+
config,
5+
lib,
6+
pkgs,
7+
...
8+
}:
49

510
let
611
cfg = config.virtualisation.lxc.lxcfs;
7-
in {
12+
in
13+
{
814
meta = {
915
maintainers = lib.teams.lxc.members;
1016
};
1117

1218
###### interface
1319
options.virtualisation.lxc.lxcfs = {
14-
enable =
15-
lib.mkOption {
16-
type = lib.types.bool;
17-
default = false;
18-
description = ''
19-
This enables LXCFS, a FUSE filesystem for LXC.
20-
To use lxcfs in include the following configuration in your
21-
container configuration:
22-
```
23-
virtualisation.lxc.defaultConfig = "lxc.include = ''${pkgs.lxcfs}/share/lxc/config/common.conf.d/00-lxcfs.conf";
24-
```
25-
'';
26-
};
20+
enable = lib.mkOption {
21+
type = lib.types.bool;
22+
default = false;
23+
description = ''
24+
This enables LXCFS, a FUSE filesystem for LXC.
25+
To use lxcfs in include the following configuration in your
26+
container configuration:
27+
```
28+
virtualisation.lxc.defaultConfig = "lxc.include = ''${pkgs.lxcfs}/share/lxc/config/common.conf.d/00-lxcfs.conf";
29+
```
30+
'';
31+
};
2732
};
2833

2934
###### implementation
@@ -34,11 +39,11 @@ in {
3439
before = [ "lxc.service" ];
3540
restartIfChanged = false;
3641
serviceConfig = {
37-
ExecStartPre="${pkgs.coreutils}/bin/mkdir -p /var/lib/lxcfs";
38-
ExecStart="${pkgs.lxcfs}/bin/lxcfs /var/lib/lxcfs";
39-
ExecStopPost="-${pkgs.fuse}/bin/fusermount -u /var/lib/lxcfs";
40-
KillMode="process";
41-
Restart="on-failure";
42+
ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/lib/lxcfs";
43+
ExecStart = "${pkgs.lxcfs}/bin/lxcfs /var/lib/lxcfs";
44+
ExecStopPost = "-${pkgs.fuse}/bin/fusermount -u /var/lib/lxcfs";
45+
KillMode = "process";
46+
Restart = "on-failure";
4247
};
4348
};
4449
};

0 commit comments

Comments
 (0)