flakes/containers/fluorite/flake.nix

113 lines
3.1 KiB
Nix
Raw Normal View History

2026-03-18 01:52:34 +11:00
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { nixpkgs, ... }:
let
name = "fluorite";
fqdn = "fluorite.lava.moe";
subnetId = "6";
subnet = x: "fd0d:1::${subnetId}:${toString x}";
host = subnet 1;
client = subnet 2;
subnet4 = x: "10.30.${subnetId}.${toString x}";
host4 = subnet4 1;
client4 = subnet4 2;
clientTun = "100.67.2.101";
2026-03-18 01:52:34 +11:00
modules = [
./configuration.nix
2026-03-18 03:14:59 +11:00
{
networking.useHostResolvConf = false;
2026-06-17 00:12:01 +10:00
networking.nameservers = [ "8.8.8.8" ];
2026-03-18 03:14:59 +11:00
}
2026-03-18 01:52:34 +11:00
];
in {
nixosConfigurations.container = nixpkgs.lib.nixosSystem {
inherit modules;
};
nixosModule = { config, ... }: let
hostfqdn = "${config.networking.hostName}.lava.moe";
altfqdn = "fluorite.${hostfqdn}";
# TODO: HACK
listenAddr = if (config.networking.hostName == "alyssum")
then [ "100.67.2.1" ]
else [ "10.0.0.1" "[fd0d::1]" "100.67.1.1" ];
in {
networking.nat = {
enable = true;
enableIPv6 = true;
internalInterfaces = [ "ve-${name}" ];
};
2026-03-18 03:43:35 +11:00
networking.firewall.allowedTCPPorts = [ 50300 ];
2026-03-18 01:52:34 +11:00
services.nginx.virtualHosts."${fqdn}" = {
useACMEHost = "lava.moe";
forceSSL = true;
locations."/".proxyPass = "http://${clientTun}:5030";
listenAddresses = listenAddr;
2026-03-18 01:52:34 +11:00
};
security.acme.certs.${hostfqdn} = { extraDomainNames = [ "*.${hostfqdn}" ]; };
services.nginx.virtualHosts."${altfqdn}" = {
useACMEHost = hostfqdn;
forceSSL = true;
locations."/".proxyPass = "http://${clientTun}:5030";
listenAddresses = listenAddr;
};
systemd.tmpfiles.rules = [
"d /persist/containers/${name} 755 root users"
"d /persist/media/music 075 nobody users"
];
2026-03-18 01:52:34 +11:00
containers.${name} = {
autoStart = true;
privateNetwork = true;
2026-06-17 00:56:02 +10:00
enableTun = true;
2026-03-18 01:52:34 +11:00
hostAddress = host4;
localAddress = client4;
hostAddress6 = host;
localAddress6 = client;
# privateUsers = "pick";
nixpkgs = nixpkgs;
ephemeral = true;
config = { imports = modules; };
specialArgs = { inherit fqdn; };
2026-03-18 03:43:35 +11:00
forwardPorts = [
{
containerPort = 50300;
hostPort = 50300;
protocol = "tcp";
}
];
2026-03-18 01:52:34 +11:00
bindMounts."persist" = {
hostPath = "/persist/containers/${name}";
mountPoint = "/persist";
isReadOnly = false;
};
2026-03-18 21:39:02 +11:00
bindMounts."music" = {
2026-03-18 01:52:34 +11:00
hostPath = "/persist/media/music";
2026-03-18 21:39:02 +11:00
mountPoint = "/binds/music";
2026-03-18 01:52:34 +11:00
isReadOnly = true;
};
2026-03-18 02:09:54 +11:00
bindMounts."slskd_env" = {
hostPath = config.age.secrets.slskd_env.path;
mountPoint = "/binds/slskd_env";
isReadOnly = true;
};
bindMounts."tailscale_auth" = {
hostPath = config.age.secrets.tailscale_auth.path;
mountPoint = "/binds/tailscale_auth";
isReadOnly = true;
};
2026-03-18 01:52:34 +11:00
# flake = "path:" + ./.;
};
};
};
}