containers

This commit is contained in:
mjallen18
2025-10-05 22:16:44 -05:00
parent ee48ca08bd
commit 02b5dd32a2
5 changed files with 31 additions and 70 deletions

View File

@@ -49,31 +49,42 @@ rec {
{
name,
localAddress ? "127.0.0.1",
port ? "80",
ports ? [ "80" ],
bindMounts ? { },
config ? { },
}:
{ lib, ... }:
{
containers.${name} = {
inherit localAddress bindMounts config;
inherit localAddress bindMounts;
config = config // {
networking = {
firewall = {
enable = true;
allowedTCPPorts = ports;
};
# Use systemd-resolved inside the container
# Workaround for bug https://github.com/NixOS/nixpkgs/issues/162686
useHostResolvConf = lib.mkForce false;
};
services.resolved.enable = true;
system.stateVersion = "23.11";
};
autoStart = lib.mkDefault true;
privateNetwork = lib.mkDefault true;
hostAddress = lib.mkDefault "10.0.1.3";
};
networking = {
nat = {
forwardPorts = [
{
destination = lib.mkDefault "${localAddress}:${toString port}";
sourcePort = lib.mkDefault port;
}
];
};
nat.forwardPorts = map (port: {
destination = lib.mkDefault "${localAddress}:${toString port}";
sourcePort = lib.mkDefault port;
}) ports;
firewall = {
allowedTCPPorts = [ port ];
allowedUDPPorts = [ port ];
allowedTCPPorts = ports;
allowedUDPPorts = ports;
};
};
};