Skip to content

Commit 70f2801

Browse files
committed
single ip per container
1 parent 73c35e7 commit 70f2801

3 files changed

Lines changed: 13 additions & 71 deletions

File tree

nix/container-module.nix

Lines changed: 6 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,6 @@ in
1717
Folder with configuration files.
1818
'';
1919
};
20-
21-
local-resolve = {
22-
enable = lib.mkOption {
23-
type = lib.types.bool;
24-
default = true;
25-
example = false;
26-
description = ''
27-
Use container hosted resolver instead of sharing host.
28-
'';
29-
};
30-
};
31-
32-
mDNS = {
33-
resolve = lib.mkOption {
34-
type = lib.types.bool;
35-
default = true;
36-
example = false;
37-
description = ''
38-
Resolve mDNS (using avahi).
39-
'';
40-
};
41-
42-
publish = lib.mkOption {
43-
type = lib.types.bool;
44-
default = true;
45-
example = false;
46-
description = ''
47-
Publish mDNS (using avahi).
48-
'';
49-
};
50-
};
5120
};
5221
};
5322

@@ -57,16 +26,19 @@ in
5726
{ isNspawnContainer = true; }
5827
else
5928
{ isContainer = true; };
29+
6030
nixpkgs.hostPlatform =
6131
if (builtins.pathExists "${cfg.xnode-config}/host-platform") then
6232
builtins.readFile "${cfg.xnode-config}/host-platform"
6333
else
6434
"x86_64-linux";
35+
6536
system.stateVersion =
6637
if (builtins.pathExists "${cfg.xnode-config}/state-version") then
6738
builtins.readFile "${cfg.xnode-config}/state-version"
6839
else
6940
config.system.nixos.release;
41+
7042
systemd.services.pin-state-version = {
7143
wantedBy = [ "multi-user.target" ];
7244
description = "Pin state version to first booted NixOS version.";
@@ -79,6 +51,7 @@ in
7951
fi
8052
'';
8153
};
54+
8255
networking.hostName = lib.mkIf (builtins.pathExists "${cfg.xnode-config}/hostname") (
8356
builtins.readFile "${cfg.xnode-config}/hostname"
8457
);
@@ -105,26 +78,7 @@ in
10578
};
10679
};
10780

108-
networking.useHostResolvConf = lib.mkIf cfg.local-resolve.enable false;
109-
services.resolved = lib.mkIf cfg.local-resolve.enable {
110-
enable = true;
111-
llmnr = "false";
112-
extraConfig = ''
113-
MulticastDNS=no
114-
''; # Avahi handles mDNS
115-
};
116-
systemd.services.systemd-resolved.serviceConfig.ProtectHome = lib.mkIf cfg.local-resolve.enable (
117-
lib.mkForce false
118-
);
119-
120-
services.avahi = {
121-
enable = lib.mkIf (cfg.mDNS.resolve || cfg.mDNS.publish) true;
122-
nssmdns4 = lib.mkIf cfg.mDNS.resolve true;
123-
publish = lib.mkIf cfg.mDNS.publish {
124-
enable = true;
125-
addresses = true;
126-
};
127-
openFirewall = lib.mkIf cfg.mDNS.publish true;
128-
};
81+
networking.useHostResolvConf = false;
82+
services.resolved.enable = true;
12983
};
13084
}

nix/dns-module.nix

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -216,34 +216,22 @@ in
216216
};
217217

218218
systemd.network.networks = {
219-
"80-container-vz" = {
219+
"80-container-ve" = {
220220
matchConfig = {
221-
Kind = "bridge";
222-
Name = "vz-*";
221+
Kind = "veth";
222+
Name = "ve-*";
223223
};
224224
networkConfig = {
225-
Address = "0.0.0.0/22"; # Cannot have more than 1024 interfaces linked to bridge (linux kernel limitation), so larger subnet mask doesn't make sense
225+
Address = "0.0.0.0/32"; # Single ip address
226226
LinkLocalAddressing = "no";
227227
DHCPServer = "yes";
228-
IPMasquerade = "both";
228+
IPMasquerade = "yes";
229229
LLDP = "no";
230230
EmitLLDP = "no";
231231
IPv6AcceptRA = "no";
232232
IPv6SendRA = "yes";
233233
};
234234
};
235-
"80-container-vb" = {
236-
matchConfig = {
237-
Kind = "veth";
238-
Name = "vb-*";
239-
};
240-
networkConfig = {
241-
"KeepMaster" = "yes";
242-
"LinkLocalAddressing" = "no";
243-
"LLDP" = "no";
244-
"EmitLLDP" = "no";
245-
};
246-
};
247235
};
248236
};
249237
}

nix/os/boot.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ in
9898
# Emulate UEFI on BIOS to allow UKI booting
9999
# https://github.com/NixOS/nixpkgs/issues/124132
100100
# https://wiki.archlinux.org/title/Clover#chainload_systemd-boot
101+
# https://github.com/acidanthera/OpenCorePkg/blob/master/Utilities/LegacyBoot/BootInstallBase.sh
101102
(lib.optionalString (boot == "BIOS") ''
102103
oc=${
103104
let
@@ -141,8 +142,7 @@ in
141142
done
142143
143144
cp $boot2 "$esp/boot"
144-
mkdir -p "$esp/EFI"
145-
cp -a "$oc/${arch}/EFI/OC" "$esp/EFI/OC"
145+
mkdir -p "$esp/EFI/OC"
146146
mv "$tmp/uki.efi" "$esp/EFI/OC/OpenCore.efi"
147147
'')
148148

0 commit comments

Comments
 (0)