54 lines
1.4 KiB
Nix
54 lines
1.4 KiB
Nix
{ lib, ... }:
|
|
|
|
let
|
|
yggaddr = import ../yggaddr.nix;
|
|
|
|
containerFunc = name:
|
|
# Generate a container expression from the directory at `name`.
|
|
with builtins;
|
|
let
|
|
hash = hashString "sha256" name;
|
|
hextet0 = substring 0 4 hash;
|
|
hextet1 = substring 4 4 hash;
|
|
in {
|
|
inherit name;
|
|
value = {
|
|
# These are attributes common to each container
|
|
# from the perspective of the host.
|
|
autoStart = true;
|
|
privateNetwork = true;
|
|
hostBridge = "br0";
|
|
localAddress6 = "${yggaddr.prefix}:${hextet0}:${hextet1}:c3d2/64";
|
|
# Generate a deterministic IPv6 address for the container.
|
|
# This address is accessible within HQ and Yggdrasil but not from ARPANET.
|
|
config = { ... }: {
|
|
imports = [ ../../../lib (./. + "/${name}") ];
|
|
c3d2 = {
|
|
isInHq = true;
|
|
mapHqHosts = true;
|
|
hq.interface = "eth0";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
containerDir = builtins.readDir ../containers;
|
|
containerSubdirs =
|
|
lib.filterAttrs (_: kind: kind == "directory") containerDir;
|
|
containerNames = builtins.attrNames containerSubdirs;
|
|
|
|
containers = builtins.listToAttrs (map containerFunc containerNames);
|
|
|
|
in {
|
|
boot.enableContainers = true;
|
|
inherit containers;
|
|
|
|
imports = [ ../../../lib/lxc ];
|
|
lxc.containers = {
|
|
trivial = {
|
|
nixos-config = "/tmp/trivial.nix";
|
|
lxc = {};
|
|
};
|
|
};
|
|
}
|